0

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.

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

2 Comments

What should be the type of my User.Gender attributes?
It should be the type SelectList as mentioned

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.