开发者

How to redirect to another page when selected dropdown item is changed?

开发者 https://www.devze.com 2023-01-10 10:20 出处:网络
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\")%>

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号