开发者

jQuery button navigate to an action controller with route value?

开发者 https://www.devze.com 2023-02-28 07:37 出处:网络
At this moment I used a link like this: @Html.ActionLink(\"Back to se开发者_Python百科arch\", \"Search\", \"Affaire\", (SearchCriteria) Session[\"SearchCriteria\"], null)

At this moment I used a link like this:

@Html.ActionLink("Back to se开发者_Python百科arch", "Search", "Affaire", (SearchCriteria) Session["SearchCriteria"], null)

Where I navigate back to my search list page with my search criteria as route value. Now I would like to use a jQuery button to replace my action link but I don't know how to proceed.

I would like somethink like this:

$("#buttonBackToSearch").click(function () {
    // here somethink to navigate back to my list with route value parameter filled     
});

Any help will be greatly appreciated.

Thanks.


ActionLink renders a URL that's used to perform the routing. You have to translate the building of the route URL in your JQuery button handler... you could also try using the UrlHelper instead to generate the URL server-side and embed it in the script as:

var url = '@(new UrlHelper(..).Action(..))';
window.location = url;
//Are you using a hyperlink and need to set the href, or redirect on button click?

As long as you only need to generate the URL from the server, and not have any client-side logic change it. If the client needs to change the route values, then you need to rebuild the ActionLink logic on the client.

HTH.

0

精彩评论

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