简体   繁体   中英

How to redirect to a specific action in mvc 4 controller

i have two forms in a page one for the search bar and the other one the registration form, now my problem is that after registration, when the page is submitted, instead of posting to the action of the registration form, it posts to search bar action method.

Now thinking that its because of the two forms that am having this misnomer, i removed the search bar form and implemented using javascript. This solved the problem by letting the registration form post to the correct action method, but the problem now is that the registration forms action method redirects to the search bar action method after it has finished processing the page, when it is suppose to deliver the registration complete page.

So my question is how can i prevent the registration action method from redirecting to the search bar action method.

Use something like this. Specify the action and controller that you want.

return RedirectToAction("Action", "Controller");

Within action of your controller, you can write your redirection code as:

[HttpPost]
public ActionResult YourActionName()
{
  // your logic to perform some action.
  // Now you can redirect to another action( may be of another controller) by such as:

  return RedirectToAction("YourActionName", "YourControllerName", ParameterForAction);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM