Reputation: 773
I have some problem with redirecting to some action basicly if I have no paramers on route or parameter which calls Id it works fine, yet when i add some different parameters to route RedirectToAction does not work, it throws an error: No route in the route table matches the supplied values.
[Route("First")]
public ActionResult First()
{
//THIS DOESN'T WORK
//return RedirectToAction("Second", new { area = "plans"});
//THIS WORKS
return RedirectToAction("Third", new { id = "12" });
}
[Route("Second/{area}")]
public ActionResult Second(string area)
{
return new ContentResult() { Content = "Second : " + area};
}
[Route("Third/{id}")]
public ActionResult Third(string id)
{
return new ContentResult() { Content = "Third " + id };
}
So when i enter /First it redirect correctly to Third but to Second it throw error.
I don't have anything extra in RouteConfig just:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
}
Upvotes: 3
Views: 8649
Reputation: 38598
Probably, you are conflicting the area
parameter with area
route parameters. Areas is a resource from Asp.Net MVC with the following definition:
Areas are logical grouping of Controller, Models and Views and other related folders for a module in MVC applications. By convention, a top Areas folder can contain multiple areas. Using areas, we can write more maintainable code for an application cleanly separated according to the modules.
You could try to rename this parameter and use it, for sample, try to rename the area
to areaName
:
[Route("First")]
public ActionResult First()
{
return RedirectToAction("Second", new { areaName= "plans"});
}
[Route("Second/{areaName}")]
public ActionResult Second(string areaName)
{
return new ContentResult() { Content = "Second : " + areaName};
}
Upvotes: 3