Lets say I have a a table called… Person, I guess, and it has the columns Name, Email, AgeGroupId.
AgeGroupId is an int, which relates to the table AgeGroup.
Agegroup only has two columns: Id, and AgeGroupName.
Now, In my view, which is a page to edit a ‘person’, I want a dropdown box that has EVERY AgeGroupName as the text, and the Id as the value.
This way, later on, I can add a new ‘age group’ into my age group table, and all my drop down boxes will update. Or is there a better way I should be doing this?
I’m currently passing in my model, and doing this:
@Html.DropDownListFor(model => model.AgeGroupId, @agegroups)
and at the top of the view, i’m making a SelectList with hardcoded values. I don’t want them hard-coded in, I don’t think? What would I do instead of @agegroup to get the list from the AgeGroups table?
Thanks.
The correct way seems to be from Kamyars edit, on the msdn blog here:
http://blogs.msdn.com/b/joecar/archive/2011/04/15/asp-net-mvc-3-tools-update.aspx