7

How can I set selected Item of Html.DropDownList to Request.QueryString["JobType"]

<td class="data"><%= Html.DropDownList("MaintJobTypes")%>

some thing to:

<td class="data"><%= Html.DropDownList("MaintJobTypes").selectedItem = Request.QueryString["JobType"]%>
Sreedhar
  • 29,307
  • 34
  • 118
  • 188
  • See [this question](http://stackoverflow.com/questions/624828/asp-net-mvc-html-dropdownlist-selectedvalue), it will solve your problem. – expertCode May 26 '11 at 16:13

1 Answers1

8

If you set ViewData["MaintJobTypes"] equal to the value of the item you want to select, Html.DropDownList will pick that up and set the selected value. You can also use a property on Model as long as the name of the drop down list matches the model property.

Alternatively you can use the SelectList helper which provides a list of items and the selected one.

More examples and details available here:

http://codeclimber.net.nz/archive/2009/08/10/how-to-create-a-dropdownlist-with-asp.net-mvc.aspx

Samuel Neff
  • 73,278
  • 17
  • 138
  • 182