How to set ID and text in html.label helper in mvc2

I want to set ID and Text attribute in html.label helper in mvc2

<%:html.label<have to set ID and Text properties here>%> 

Plz help me.

+7
source share
1 answer

The Html.Label method returns the HTML label element and the name of the property property that is represented by the specified expression. For example:

ASPX Syntax

 <%: Html.Label("Text Content", new { id = "labelId" })%> 

Razor Syntax

 @Html.Label("Text Content", new { id = "labelId" }) 

The second parameter is htmlAttributes, so you can add any html attribute that you want as a property of this anonymous object. For example:

new { id = "id-element", name = "name-element", size = 10, @class = "css-class" }

Idfor

If you want to take an Id using the html helper, try using:

 @Html.IdFor(model => model.Property) 
+11
source

All Articles