禁用EditorFor

RG-*_*G-3 3 c# asp.net-mvc asp.net-mvc-3

我有一个这样的EditorFor HTML帮助:

<td>@Html.EditorFor(m => m.Name, belowLevel ? disabledHtmlOptions : null)</td>
Run Code Online (Sandbox Code Playgroud)

-

object disabledHtmlOptions = new { disabled = "disabled" };
Run Code Online (Sandbox Code Playgroud)

我想每次都做这个残疾人.我怎么做?我不想做数据注释,因为这个属性也在其他视图中使用.只有在这个视图上我想禁用它.

Pee*_*okk 8

MVC 5.1现在允许在EditorFor中传递HTML属性(请参阅此答案).所以你可以这样做:

@Html.EditorFor(model => m.Name, new { htmlAttributes = new { disabled = "disabled" } })
Run Code Online (Sandbox Code Playgroud)