1

如何使以下字段只读..?

<%: Html.TextBoxFor(x => x.Age, new { value = "0"}) %>
4

2 回答 2

7

您可以设置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);
于 2013-02-28T10:08:01.000 回答
0

使用以下

<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly" }) %>

您可以在调用这样的助手时一次传递多个属性

<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly", @class="Text", style="INLINE STYLE" }) %>
于 2013-02-28T10:21:25.473 回答