0

i got a checkbox that i would like to be disabled ? i am using asp.net mvc 2 and jquery.

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

public class MyModel
{
  public bool flag {get;set;}
}
1
  • have you thought of using Html.CheckBoxFor? Commented Jul 6, 2011 at 4:32

1 Answer 1

3

you can either use jquery to disable your checkbox using

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

or if you want to do it on server side you have to fall back to checkboxfor helper like

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

or you can write your own editor template that can consume additionalViewData parameter of Html.EditorFor

Sign up to request clarification or add additional context in comments.

2 Comments

the first option requires Javascript. The second option is the better way to go.
yep second one is certainly better

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.