ASP.NET MVC的HtmlHelper - 我怎么不写的属性值? [英] ASP.NET MVC HtmlHelper - how do I write an attribute without a value?
本文介绍了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 = "" })
这篇关于ASP.NET MVC的HtmlHelper - 我怎么不写的属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文