Hi Avnish,
There are three method in MVC to redirect to other action as:
- RedirectToAction()
- Redirect()
- RedirectToRoute()
All method make new request.
RedirectToAction():
Use it if you know ActionName within a Controller as:
RedirectToAction("ActionName", new { });
Use it if you know ActionName and ControllerName as:
RedirectToAction("ActionName", "ControllerName", new { });
Redirect():
Use it if you do not know actionname or ControllerName, just you know only path as:
Redirect("Home/MyIndex");
RedirectToRoute():
Use it if you know specific routename from route config or global.asax as:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//Tutorial Routing Starts
routes.MapRoute(
"MyRoute", // Route name
"Login", // URL with parameters
new { controller = "Account", action = "Login" } // Parameter defaults
);
}
RedirectToRoute("MyRoute", new { });
Posted On:
18-May-2015 20:26