我的表单中有两个字段,应该从模型中预先填写。这些字段是只读的。对于“电子邮件”字段,我的表单已正确预填充。但是对于我的用户名字段,value属性保持为空。我似乎无法找出为什么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" })
</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>
在我视图的随机位置打印@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>
答案 0 :(得分:-2)
问题就像TextBoxFor HtmlHelper一样。你有可能在/ Views / Shared / EditorTemplates中有一个编辑模板吗?