C# HTML帮助标记文本框使其为只读
如何将以下字段设置为只读C# HTML帮助标记文本框使其为只读,c#,html,asp.net-mvc,html-helper,C#,Html,Asp.net Mvc,Html Helper,如何将以下字段设置为只读 <%: Html.TextBoxFor(x => x.Age, new { value = "0"}) %> x.Age,新的{value=“0”})%> 您可以设置只读属性: <%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly" }) %> <%= Html.TextBoxFor(x => x.Age, new { disabled = "disab
<%: Html.TextBoxFor(x => x.Age, new { value = "0"}) %>
x.Age,新的{value=“0”})%>
您可以设置只读属性:
<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly" }) %>
<%= Html.TextBoxFor(x => x.Age, new { disabled = "disabled" }) %>
就设置文本框的默认值而言,我建议您在填充模型时在控制器上执行此操作:
MyViewModel model = ...
model.Age = 0;
return View(model);
您可以设置readonly
属性:
<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly" }) %>
<%= Html.TextBoxFor(x => x.Age, new { disabled = "disabled" }) %>
就设置文本框的默认值而言,我建议您在填充模型时在控制器上执行此操作:
MyViewModel model = ...
model.Age = 0;
return View(model);
使用下列内容
<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly" }) %>
x.Age,新的{@readonly=“readonly”}]>
像这样调用帮助程序时,可以一次传递多个属性
<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly", @class="Text", style="INLINE STYLE" }) %>
x.Age,新的{@readonly=“readonly”,“@class=“Text”,style=“INLINE style”})%>
使用以下命令
<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly" }) %>
x.Age,新的{@readonly=“readonly”}]>
像这样调用帮助程序时,可以一次传递多个属性
<%= Html.TextBoxFor(x => x.Age, new { @readonly = "readonly", @class="Text", style="INLINE STYLE" }) %>
x.Age,新的{@readonly=“readonly”,“@class=“Text”,style=“INLINE style”})%>
@karthik,这个问题可能很复杂,但Darin的第二个建议对这个问题很重要。因为这只适用于强类型-helpers@karthik,这个问题可能不明确,但达林的第二个建议对这个问题很重要。因为这只适用于强类型助手