19
I'm trying to teach myself MVC3. Im converting from webforms.
I need to create a view model that includes a dropdown list that I can pass to the controller and eventually render in the View.
How can I accomplish this? I have the skeleton but I dont know what the code is to actually create the name value pairs for the view.
namespace DH.ViewModels
{
public class SharedLayoutViewModel
{
public IEnumerable<SelectListItem> Products
{
//some code to setup the value/name pairs to be rendered in the view.
//example:
//<option value="1">Mustard</option>
//<option value="2">Ketchup</option>
//<option value="3">Mayo</option>
//<option value="4">Relish</option>
//<option value="5">BBQ</option>
}
}
}
Thanks