I have 2 dropdown lists that I'm putting on to the page as follows. I can't get either to work:
<%=Html.DropDownList("CategoryId", Model.CategoryList, "Select a category to view")%>
and
<%=Html.DropDownList() For(m => m.SearchExpression) %>
What I need is to be able to redirect to a page when one of the items is selected and 开发者_运维百科I click submit.
Can somebody please outline the steps I need to take to achieve this?
<% using( Html.BeginForm() ) { %>
<%= Html.DropDownListFor( m => m.SearchExpression %>
<input type="submit" value="Submit" />
<% } %>
You will have a controller with a POST action:
[HttpPost]
public ActionResult Foo( ... )
{
return RedirectToAction( ... );
// OR return RedirectToRoute( ... );
}
If your working in asp.net, you can put code in the SelectedIndexChanged event attached to the dropdown. Within this event, you can call Reponse.Redirect(url).
精彩评论