我可以知道为什么我的文本框的htmlAttribute不起作用吗?我使用的是@ Html.BeginForm,只有部分超链接没有跟随另一个。
以下是我的代码。
TRichedit
如果我删除
@using (Html.BeginForm())
{
@token
<div class="form-horizontal">
<h4>StoreDetail</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.StoreId)
<div class="form-group">
@Html.LabelFor(model => model.NoOfSeat, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.NoOfSeat, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NoOfSeat, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Hyperlink", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("Hyperlink", ViewData["Hyperlink"], new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
</div>
</div>
它会产生相同的视图,就像它不起作用一样。
答案 0 :(得分:4)
替换此语法
new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } }
与
new { @class = "form-control", @readonly = "readonly" }
EditorFor
仅限助手 New Features in ASP.NET MVC 5.1 支持您使用的语法。