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"]%>
1
  • See this question, it will solve your problem. Commented May 26, 2011 at 16:13

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.