@Html.EditorFor() Renders DropDownList Instead of CheckBox

Jonathan Wood picture Jonathan Wood · Dec 12, 2011 · Viewed 7.7k times · Source

I'm new from WebForms to MVC 3 and have an issue with the @Html.EditorFor() helper method.

I have a strongly typed view that represents data from a database, and one of the methods is of type bool?. I'd like this to appear as a checkbox, but instead it appears as a dropdownlist with the options "Not Set", "True" and "False".

What is the simplest way to covert this to a regular checkbox?

I understand that I could change the data type to a plain old bool, but this is a large EF entity I'm using and it seems a pain to have to recreate the entire class just for this. I also realize I'll lose the ability to track the "not set" state, but showing a simple checkbox is more important to me.

Answer

Paul picture Paul · Dec 12, 2011

Use the checkbox helper method instead, @Html.CheckBoxFor()

It's rendering a drop down list as a check box wouldn't be able to provide the value "not set".