Why can't I pass in html attributes to EditorFor()
? eg;
<%= Html.EditorFor(model => model.Control.PeriodType,
new { disabled = "disabled", readonly = "readonly" }) %>
I don't want to use metadata
Update: The solution was to call this from the view :
<%=Html.EditorFor( model => model.Control.PeriodEndDate, new {Modifiable=model.Control.PeriodEndDateModifiable})%>
and use ViewData["Modifiable"]
in my custom EditorTemplates/String.ascx where I have some view logic that determines whether to add readonly and/or disabled attributes to the input
The anonymous object passed into EditorFor()
is a parameter called additionalViewData
and its properties are passed to the editor template in the ViewData
collection.