I want to get the name value not ID value from SelectList in mvc.
Here is my code
Controller
var occupationList = new SelectList(new[]
{
new { ID = 1, Name = "Student" },
new { ID = 2, Name = "House Wife" },
new { ID = 3, Name = "Business Man" },
new { ID = 4, Name = "Service Man" },
},
"ID", "Name", 1);
ViewData["occupationList"] = occupationList;
return View();
View
@Html.DropDownList("Occupation", ViewData["occupationList"] as SelectList, new {@class="control-label", style="width:250px;" })
Now, when I select the item from dropdownlist at that time it shows the selected item but it store the ID value in the database.
For ex : I select the Student
Name value from the dropdownlist and save it. Now, in database it store the 1
value.
But I dont want to store the ID value i.e. 1
. I want to store the Name value i.e. Student
in database.
Thank You.