Redirecting to another page in ASP.NET MVC using JavaScript/jQuery

前端 未结 6 1599
执念已碎
执念已碎 2020-12-12 11:46

I want to redirect from one page to another page in ASP.NET MVC 3.0 using JavaScript/jQuery/Ajax. On button click event I have written JavaScript code like below.

         


        
6条回答
  •  醉话见心
    2020-12-12 12:16

    This could be done by using a hidden variable in the view and then using that variable to post from the JavaScript code.

    Here is my code in the view

    @Html.Hidden("RedirectTo", Url.Action("ActionName", "ControllerName"));
    

    Now you can use this in the JavaScript file as:

     var url = $("#RedirectTo").val();
     location.href = url;
    

    It worked like a charm fro me. I hope it helps you too.

提交回复
热议问题