Jseb
Jseb

Reputation: 1934

ASP.net MVC 4 Drop Down List

I am a bit lost on the concept of drop down list in MVC 4.

I have to models

Gender - int ID - string Title

User -string FirstName - Gender -...

I am bit unsure how to tackle it, to keep it clean and simple.

For the type in my class users, should it be Gender because its the name of the table or should it be this IEnumerable?

If its if so i am missing other things?

Also should i provide something specific to the controllers? or how do I display the dropdownlist in C# MVC 4 Razor code.

Upvotes: 0

Views: 744

Answers (1)

Mark Redman
Mark Redman

Reputation: 24515

Have a look at the SelectList class http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlist%28v=vs.108%29.aspx

This goes in your model, then you can create a dropdownlist like this:

@Html.DropDownList("GenderId", Model.Genders)

Upvotes: 2

Related Questions