对于attribute =“value”,我使用
@Html.TextBoxFor(x => x.Email, new { type = "email", @class = "form-control",
placeholder="Email address" })
它给了我:
<input class="form-control" id="Email" name="Email" placeholder="Email address"
type="email" value="" />
如何添加单个属性,因此我需要自定义和自动对焦:
<input class="form-control" id="Email" name="Email" placeholder="Email address"
type="email" value="" required autofocus />
谢谢!
答案 0 :(得分:4)
如果您使用string.Empty
,您将在生成的html中获得一个空属性
@Html.TextBoxFor(x => x.Email, new { type = "email", @class = "form-control",
placeholder = "Email address", required = string.Empty, autofocus = string.Empty })