ASP.Net MVC Redirect To A Different View
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.
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");
}