Make checkbox disabled in asp.net mvc 2 and jquery

Do I have a checkbox that I would like to disable? I am using asp.net mvc 2 and jquery.

<%= Html.EditorFor(p=>p.flag) %>

public class MyModel
{
  public bool flag {get;set;}
}
0
source share
1 answer

you can use jquery to disable your checkbox using

$('#flag').attr('disabled', true);

or if you want to do this on the server side, you should return to checkbox for helper, for example

<%:Html.CheckBoxFor(x => x.flag, new { disabled = "disabled" }) %>

or you can write your own editor template, which can consume an additional parameter ViewData Html.EditorFor

+3
source

All Articles