How Do I Conditionally Specify Whether HTML Input Is Disabled/readonly OR NOT?
Here's a sample of what I'm trying to achieve: @Html.EditorFor(m => m.Description, new { htmlAttributes = new { @class = 'form-control', @readonly = Mod
Solution 1:
HTML :-
@Html.EditorFor(m => m.Description,
new { htmlAttributes =
new
{
@class = "form-control"
}
});
Try using jQuery as shown :-
if(@Json.Encode(Model.IsReadOnly))
{
$('#Description').attr('readonly','readonly')
}
if(@Json.Encode(Model.IsDisabled))
{
$('#Description').attr('disabled','disabled')
}
Post a Comment for "How Do I Conditionally Specify Whether HTML Input Is Disabled/readonly OR NOT?"