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

后端 未结 1 451
执笔经年
执笔经年 2021-01-11 19:13

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

<%:html.label%>

Plz h

相关标签:
1条回答
  • 2021-01-11 19:27

    The Html.Label method returns an HTML label element and the property name of the 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 the htmlAttributes, so, you can add any html attribute 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 the Id by a html helper method, try to use:

    @Html.IdFor(model => model.Property)
    
    0 讨论(0)
提交回复
热议问题