ASP.NET MVC使用模型填充Html属性

时间:2011-10-31 19:02:29

标签: html asp.net-mvc

而不是在TextBoxFor元素中硬编码“disabled =”true“”,而是希望它从模型中拉出来。模型属性(Model.InvoicedApprovedBy)将设置为“”(启用)或“禁用=”禁用“(禁用)

<%= Html.TextBoxFor(m => m.WorkingModel.Detail.ApprovedBy, new { id = "InvoiceApprovedBy", disabled="true", style = "width: 203px; " })%>

我想做这样的事情:

<%= Html.TextBoxFor(m => m.WorkingModel.Detail.ApprovedBy, new { id = "InvoiceApprovedBy", Model.InvoicedApprovedBy, style = "width: 203px; " })%>

它设置一个名为“InvoicedApprovedBy”的html属性,而不是仅将字符串“disabled =”禁用“”。如何让它放置字符串?

1 个答案:

答案 0 :(得分:1)

 <%= Html.TextBoxFor(m => m.WorkingModel.Detail.ApprovedBy, new { id = "InvoiceApprovedBy",  disabled = Model.InvoicedApprovedBy, style = "width: 203px; " })%>

您不需要将model属性设置为“disabled = disabled”,只需“禁用”。