views:

38

answers:

1

Hi all,

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.

Thanks in advance.

A: 

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.

Darin Dimitrov