Skip to content Skip to sidebar Skip to footer

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?"