I have this code in my view. I need to display the selected value that is comming from the database in the Dropdownlist.
<select id="PeopleClass" name="PeopleClass">
<option value="1">Name1</option>
<option value="2">Name2</option>
<option value="3">Name3</option>
</select>
Now I am getting default as Name1 but what ever the database value I am coming I need to display in the view?
Can anybody help me out?
DropDownListForis the method you can use: check this for more details: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.selectextensions.dropdownlistfor.aspxI would suggest you Create
into a
IEnumerable<SelectListItem>and bind it when you render your view with your selected value from database.lastly in your view, bind the dropdown list with
ViewData["ddl"]