C#ASP.NET MVC 4 - html.TextBoxFor值属性为空

时间:2016-03-23 20:37:48

标签: c# asp.net-mvc

我的表单中有两个字段,应该从模型中预先填写。这些字段是只读的。对于“电子邮件”字段,我的表单已正确预填充。但是对于我的用户名字段,value属性保持为空。我似乎无法找出为什么Username字段的值仍为空。

enter image description here 两个值都填入模型中。 enter image description here

        <div class="form-group input-group required-field-block">
            <span class="input-group-addon">
                <i class="glyphicon glyphicon-user"></i>
            </span> 
            @Html.TextBoxFor(m => m.UserName, new { @class = "form-control", placeholder = "Username", readOnly = "readonly" })
        </div>
        <div class="form-group input-group required-field-block">
            <span class="input-group-addon">
                <i class="glyphicon glyphicon-envelope"></i>
            </span>
            @Html.TextBoxFor(m => m.Email, new { @class = "form-control", placeholder = "Email", readOnly = "readonly" })
        </div>

预先填写电子邮件: enter image description here 用户名不是(注意值属性): enter image description here

来自fiddler的结果: enter image description here

在我视图的随机位置打印@Model.UserName,返回正确的值

        <div class="form-group input-group required-field-block">
            <span class="input-group-addon">
                <i class="glyphicon glyphicon-user"></i>
            </span>
            @Html.TextBoxFor(m => m.UserName, new { @class = "form-control", placeholder = "Username", readOnly = "readonly" }) <!-- NO VALUE -->

            @Model.UserName <!-- Prints name perfectly -->
        </div>

1 个答案:

答案 0 :(得分:-2)

问题就像TextBoxFor HtmlHelper一样。你有可能在/ Views / Shared / EditorTemplates中有一个编辑模板吗?