Here's a sample of what I'm trying to achieve:
@Html.EditorFor(m => m.Description,
new { htmlAttributes =
new
{
@class = "form-control",
@readonly = Model.IsReadOnly,
disabled = Model.IsDisabled
}
})
The problem is that the browser treats the existence of the readonly and disabled tokens without checking for their content, so when the IsReadOnly and IsDisabled properties are false, it will still show as disabled.
Is there any simple solution for that?
@Html.EditorFor(m => m.Description, Model.IsDisabled ? (object)new { disabled = "disabled" } : (object)new { })Model.IsReadOnlyandModel.IsDisabled). If this is not a 'once off' I would consider a custom helper (and do you really want to disable controls? - they wont post back).