Reputation: 3
I started to use ASP.NET Identity, and my question is how can I add a dropdownlist for gender (Male and Female) to my database?
I added a string value called "Gender" to my "AspNetUsers" table(with migrations in the cmd)
and I want to save there the values from the dropdownlist..
I'm using MVC but I can use Web Forms as well. I saw this link: MVC4 Dropdown menu for Gender and I didn't understand how does it connect to the databse.
Thanks in advance.
Upvotes: 0
Views: 538
Reputation: 440
In Controller
ViewBag.gender=new List<SelectListItem>(){
new SelectListItem(){Text="Male", Value="Male"},
new SelectListItem(){Text="Female", Value="Female"}
} ;
In view
@Html.DropDownListFor(
x => x.GenderId,
new SelectList(ViewBag.gender as List<SelectListItem>, "Value", "Text"))
Upvotes: 1