I am new to MVC 4, i want to create a drop downmenu for listing the gender.I tried a lot but nothing helped me, also i google it but invain.Please help me in it tha thow to create dropdown menu for gender please guide me.
相关问题
- dropdown <select> for list.js
- There is no ViewData item with the key 'taskTy
- IE dropdown z-index bug
- How to create anchor href using Html.Helper [dupli
- Value cannot be null or empty.\r\nParameter name:
相关文章
- MVC CDN fallback for Style Bundle
- Add to htmlAttributes for custom ActionLink helper
- Django: Replacement for the default ManyToMany Wid
- Disable action method from being called from the a
- ASP.Net MVC 3: optgroup support in Html.DropDownLi
- User.Identity.IsAuthenticated vs WebSecurity.IsAut
- Is there a way to update asp.net mvc bundle conten
- MVC4 - ContextDependentView - What does it mean?
Create a Class for Gender
Create a list for Gender anywhere in the Controller
You will have to create a SelectList for genders in the Action that will be passed to the view.
Finally you'll add a DropDownList to the view
say we use an enum for the gender:
and we make a model like this:
make a controller like so:
then in your view, you use the DropDownListFor html helper you include the following:
the DropDownListFor html helper uses at leats these two parameters:
List<SelectListItem>()
that contains all the options in the dropdownlist.