how to display selected value in drop down list in asp.net mvc?
- by Renu123
i want to display selected value in drop down list . the value comes from the data base. for ex suppose we want to update user profile then value for gender which is previously provided by the user should get displayed as selected value. the code that i used to display is
<% string val = Convert.ToString(Model.gender);
ViewData["gen"] = val;
%>
<%= Html.DropDownList("genderList", ViewData["gen"] as SelectList) %>
but its not showing the value from the database.but viewdata get value from database but it is not showing on drop down list.
thanks in advance.