2

I am developing a MVC 5 internet application, and I wish to redirect to a controller/action result from anywhere in my application.

The controller name is "Manager", and the action result is "TestAction"

In an action result, the following code can be used:

RedirectToAction("TestAction", "Manager")

I have also coded a filter attribute as follows:

filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary{{ "controller", "Manage" }, { "action", "TestAction" } });

Is there a generic way to send the user to a specific controller, action result from anywhere in a MVC application? I specifically wish to do this in an extension method.

Thanks in advance.

Simon
  • 7,991
  • 21
  • 83
  • 163

3 Answers3

2

You can do it by simply Response.Redirect (taking the domain path and append the url).

Did you try the answer like this one https://stackoverflow.com/a/18126733/713789

Community
  • 1
  • 1
Anirudha Gupta
  • 9,073
  • 9
  • 54
  • 79
0

In your controller you can use RedirectToAction("TestAction", "Manager") to redirect and in your view you can write windows.location.href("Manager","TestAction").

0

What i've done in such cases:

Dictionary<string, object> dictionary = new Dictionary<string, object>();
//
//...add parameters...

dictionary.Add("controller", "ControllerName");//ex: Home for HomeController
dictionary.Add("action", "MyMethod");
return RedirectToRoute("Default", dictionary);//"Default" is the name of the rout you're using
チーズパン
  • 2,752
  • 8
  • 42
  • 63
Apex ND
  • 440
  • 5
  • 12