如何使以下字段只读..?
<%: Html.TextBoxFor(x => x.Age, new { value = "0"}) %>
如何使以下字段只读..?
<%: Html.TextBoxFor(x => x.Age, new { value = "0"}) %>
您可以设置readonly
属性:
<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly" }) %>
如果您想禁用文本框(与用户的只读相同,但在提交表单时其值不会发送到服务器),您可以使用该disabled
属性:
<%= Html.TextBoxFor(x => x.Age, new { disabled = "disabled" }) %>
就设置文本框的默认值而言,我建议您在填充模型时在控制器上执行此操作:
MyViewModel model = ...
model.Age = 0;
return View(model);
使用以下
<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly" }) %>
您可以在调用这样的助手时一次传递多个属性
<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly", @class="Text", style="INLINE STYLE" }) %>