adding a css class with Html.TextBox

戏子无情 提交于 2019-12-10 13:15:57

问题


Trying to add a 'class' html attribute, but I think the keyword 'class' is causing issues.

<%: Html.TextBox("name", "value", new {class: " required "})%>

Is there a workaround?


回答1:


Just prefix 'class' with an '@' as it's a reserved keyword.

<%: Html.TextBox("name", "value", new { @class: " required "})%>

If you need some background on the @ keyword, this is a good SO question to read.



来源:https://stackoverflow.com/questions/3038209/adding-a-css-class-with-html-textbox

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