Am I calling RedirectToRoute correctly?

671 views Asked by At

Am I calling RedirectToRoute correctly?


RouteConfig.cs:

routes.MapRoute(
    name: "Contact Us",
    url: "ContactUs",
    defaults: new {controller = "Home", action = "ContactUs"}
);

Handler.cs

HttpContext.Current.Response.RedirectToRoute("Contact Us", 
    new { controller = "Home", action = "ContactUs" }); 
1

There are 1 answers

0
David L On BEST ANSWER

While what you are doing works, it is also both unnecessary and overkill. The second parameter is reserved for either a RouteValueDictionary or an object used in the construction of additional routing details, which are already set as the default for the named route.

In your case, you can simply use the string name of the route, via this overload.

HttpContext.Current.Response.RedirectToRoute("Contact Us");