Question

I've been jumping through hoops to add an array of checkboxes to a View in an asp.net MVC project (using a custom jQuery plugin), but just realized it might be possible using the "in-the-box" functionality of the MVC / Razor extravaganza.

Theoretically, the following should work:

If a model has an array of bool, such as:

public bool[] chicagoBoolsFools { get; set; }

...calling this in the View:

@Html.EditorFor( model => model.chicagoBoolsFools)

...should create an array of checkboxes bound to the Model member.

Is this the case only in theory, or also in actuality?

Était-ce utile?

La solution

Unfortunately @Html.EditorFor doesn't even create checkboxes... Maybe I am misunderstanding you but I would try something more along the lines of this post.

Try stuffing a model with either a list of Checkboxes (represented by a string and a boolean value) or just a basic string property for each checkbox, which can then be rendered in the view using several @Html.CheckBoxFor calls.

@Html.CheckBox or @Html.CheckBoxFor are key here.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top