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

五迷三道 提交于 2019-12-01 03:47:37

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!