forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlHelper.Label.cs
More file actions
52 lines (42 loc) · 1.7 KB
/
HtmlHelper.Label.cs
File metadata and controls
52 lines (42 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Web.Mvc;
using Microsoft.Internal.Web.Utils;
namespace System.Web.WebPages.Html
{
public partial class HtmlHelper
{
public IHtmlString Label(string labelText)
{
return Label(labelText, null, (IDictionary<string, object>)null);
}
public IHtmlString Label(string labelText, string labelFor)
{
return Label(labelText, labelFor, (IDictionary<string, object>)null);
}
public IHtmlString Label(string labelText, object attributes)
{
return Label(labelText, null, AnonymousObjectToHtmlAttributes(attributes));
}
public IHtmlString Label(string labelText, string labelFor, object attributes)
{
return Label(labelText, labelFor, AnonymousObjectToHtmlAttributes(attributes));
}
public IHtmlString Label(string labelText, string labelFor, IDictionary<string, object> attributes)
{
if (String.IsNullOrEmpty(labelText))
{
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "labelText");
}
labelFor = labelFor ?? labelText;
TagBuilder tag = new TagBuilder("label") { InnerHtml = Encode(labelText) };
if (!String.IsNullOrEmpty(labelFor))
{
tag.MergeAttribute("for", labelFor);
}
tag.MergeAttributes(attributes, false);
return tag.ToHtmlString(TagRenderMode.Normal);
}
}
}