Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 883
Gavin Avatar asked Feb 13 '09 15:02

Gavin


People also ask

How redirect another action method in MVC?

To redirect the user to another action method from the controller action method, we can use RedirectToAction method. Above action method will simply redirect the user to Create action method.

How redirect external URL from view in MVC?

You can redirect to an external URL by using Redirect Method() or via Json Result. Asp.net MVC redirect to URL: You can do URL redirect in mvc via Controller's Redirect() method. The following example, I have given redirection to google page.

What is redirect to route in MVC?

RedirectToRouteResult is an ActionResult that returns a Found (302), Moved Permanently (301), Temporary Redirect (307), or Permanent Redirect (308) response with a Location header. Targets a registered route. It should be used when we want to redirect to a route.

How do I use RedirectToAction?

The RedirectToAction() MethodThis method is used to redirect to specified action instead of rendering the HTML. In this case, the browser receives the redirect notification and make a new request for the specified action. This acts just like as Response. Redirect() in ASP.NET WebForm.


1 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.

like image 132
John Sheehan Avatar answered Oct 13 '22 14:10

John Sheehan