I am using MVC in asp.net.
i want to change font size & color of html.label control.
so how can i make helper class of this?
I am using MVC in asp.net.
i want to change font size & color of html.label control.
so how can i make helper class of this?
Here is my code for such an extension. Note that the ParameterDictionary is my own class. I think the MVC extensions use RouteValueDictionary instead, but it seems wrong to me to rely on that so I made my own class for this specific purpose. You'll need to import the namespace containing your HtmlExtensions class into the view where you want to use these extensions (and add a reference to the project containing the class if not in your web project).
public static class HtmlExtensions
{
public static string Label( this HtmlHelper helper,
string labelFor,
string value,
object htmlAttributes )
{
TagBuilder labelBuilder = new TagBuilder( "label" );
if (!string.IsNullOrEmpty( labelFor ))
{
labelBuilder.Attributes.Add( "for", labelFor );
}
labelBuilder.MergeAttributes( new ParameterDictionary( htmlAttributes ) );
labelBuilder.SetInnerText( value );
return labelBuilder.ToString( TagRenderMode.Normal );
}
}
Usage:
<%= Html.Label( "Name", new { @class = "input-label" } ) %>
<%= Html.TextBox( "Name" ) %>
Wouldn't you just do that in the markup (style / css):
<label for="Name" ***here***>Name:</label>