Below is my RouteConfig.cs
code snippet:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "myroute",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "About", id = UrlParameter.Optional }
);
}
and in Home/Contact
I am redirecting to the route named "myroute", which maps to Home/About
. Instead of redirecting to Home/About
, it is redirecting to the same action (Home/Contact
). Below is my HomeController
code:
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
return View();
}
public ActionResult Contact()
{
return RedirectToRoute("myroute");
}
Why is the redirect to myroute
not functioning?
Any help would be appreciated. Thank you.
You could make it easier. Use Response.Redirect("Home/About") But I don't know if there are any other requirements.