Let’s say I have a View for creating a new Item. Item consists of just two properties – Name and Group.
So I want a view that has one textbox and one DropDownList. I am using DropDownList because user shouldn’t be able to type whatever he wants in the Group field – there are already some predefined groups and View should enable the user to just pick one group.
I have ItemModel class that has two properties – Name (string) and GroupId (int). My view is strongly typed to ItemModel.
My questions is following: how should I pass a list of valid groups that should be presented as a choice inside DropDownList? Should I create another property inside ItemModel just for that, or maybe pass it using ViewBag or do something something else?
In your controller you add:
In the view you add:
Basically, make a new selectionlist and pass it to a ViewBag.