I've been reading several articles about how to present choices to users. Some use ListBoxFor, some use CheckBoxFor, and then there is this thing called MultiSelectList.
What I am (was) confused about was that each example seemed to have done it a totally different way, and none of them actually used the built in "SelectListItem" class but instead always created their own.
So I originally was going to post a question asking for general clarification, but I thought it would just be representative of all the other various post and repetitive.
So let me re-phrase: How do you use a "List" or a "MultiSelectList" to present a user a list of choices, including the option for them to be displayed as a list of Check boxes?
In other words, if I have the following 2 items in my Model, how would I display each of them as a typical choice list box, or a typical Check List box?
public List<SelectListItem> Widgets1 { get; set; }
public MultiSelectList Widgets2 { get; set; }
So let's start with the Model. It is really basic and you can see that I'm just creating 3 Lists that will store the same data.
The primary difference here is that all of the examples I read, people where creating their own Item classes, where I wanted to simply use the built in "SelectListItem" class
For the Controller, because this was a learning test, I just made up the data. The key here is that I build a List of SelectListItems and then used that same list to populate all 3 demo fields of the Model to show 3 different ways to work with the same data.
Now for the view, I display each list. The first of course is a check box and the second and third are list boxes but use different underlying objects...
And finally, when the user makes their own selections (or takes the pre-selected ones) and hits submit, we can get the results in the the controller simply by...