ASP.Net MVC Redirect To A Different View

Viewed 245143

Is it possible to redirect to a different view from a controller?

For example, all my controllers inherit from a custom controller that has a constructor that I want to redirect to different view if certain criteria is not met. Hope that makes sense.

6 Answers

You can use the RedirectToAction() method, then the action you redirect to can return a View. The easiest way to do this is:

return RedirectToAction("Index", model);

Then in your Index method, return the view you want.

 if (true)
 {
   return View();
 }
 else
 {
   return View("another view name");
 }

Here's what you can do:

return View("another view name", anotherviewmodel);
return RedirectToAction("index");

This is how I use it in the controller and actionresult that needs to be redirected.

Related