Dropdownlist selected item not getting displayed in Asp.net MVC
I have implemented dropdown list in asp.net mvc using following code
In controller
int iSelectedNode=2;
ViewData["ddlModels"] = new SelectList(Models, "ModelCode", "ModelName", iSelectedNode);
In View
<%= Html.DropDownList("ModelCode", (SelectList)ViewData["ddlModels"],"--Select--", new {id="ddlModel" })%>
Still all the time i get to see text "--Select--" selected all the time.
T开发者_如何学Pythonhanks in advance.
Make sure that your Models
collection in the controller contains an element with ModelCode = 2
.
This being said as you've tagged your question with asp.net-mvc-2
checkout this answer for a better way to handle drop down lists using strongly typed views and helpers.
精彩评论