MVC查看htmlAttribute无法正常工作

时间:2016-12-23 07:21:50

标签: c# asp.net asp.net-mvc razor

我可以知道为什么我的文本框的htmlAttribute不起作用吗?我使用的是@ Html.BeginForm,只有部分超链接没有跟随另一个。

以下是我的代码。

TRichedit

Screenshot of the problem.

如果我删除

    @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>

它会产生相同的视图,就像它不起作用一样。

1 个答案:

答案 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 支持您使用的语法。

enter image description here