I have this code in the client side:
$.post('<%=Url.Action("Action_Name","Controller_Name")%>', { serverParam: clientParam}, null, null);
And this code in the server side:
[HttpPost]
public ActionResult Action_Name(string serverParam)
{
return View();
}
I currently am in a view and when i click a button i want to be redirected to Controller_Name/Action_Name/serverParam.
After the post i am sent in the action method but i still see the old view, not Action_Name
(Action_Name.aspx exists)
(I am using mvc 2)
First, you should follow the “Post/Redirect/Get” pattern by returning a redirect result instead of a view after a successful post. But that would not solve the problem you’re actually asking about.
This is doing an AJAX
POST, not a “regular”POST. So the browser isn’t going to honor a redirect response by redirecting. You could “redirect” in your response callback by settingwindow.location, but…The easiest way to do what you want is to just post the form, rather than using
$.post, which is a shortcut to$.ajax, like this: