ASP.NET MVC的HtmlHelper - 我怎么不写的属性值?
问题描述:
我希望能够写没有值的属性,如自动对焦
。现在,我可以这样做:
I would like to be able to write attributes without values, such as autofocus
. Now, I can do this:
@Html.TextBoxFor(m => m.UserName, new { autofocus = true })
不过,当然这写道:
But of course this writes:
<input id="UserName" type="text" value="" name="UserName" autofocus="True">
有没有办法让没有价值的书面属性?
Is there a way to get the attribute written without the value?
答
批评家alok_dida是正确的。
Commenter alok_dida is correct.
使用:
@Html.TextBoxFor(m => m.UserName, new { autofocus = "" })