Reputation: 2913
I am writing an MVC Application using MVC Areas. Currently we are using the following route for our display area:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Display_default",
"Display/{controller}/{action}/{id}/{id2}/{id3}/{*id4}",
new { action = "Index", id = UrlParameter.Optional , id2 = UrlParameter.Optional, id3 = UrlParameter.Optional }
);
}
And this works. However we discovered the need for a controller action with 6 parameters:
public ActionResult _MyMethod(string id, string id2, string id3, string id4, string id5, string id6)
we discovered we can add this we the current setup, however any parameter in the url after the forth id is just concatenated into the 4th id parameter.
We tried to extend the route to accept the number of parameters that we needed like so:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Display_default",
"Display/{controller}/{action}/{id}/{id2}/{id3}/{id4}/{id5}/{*id6}",
new { action = "Index", id = UrlParameter.Optional , id2 = UrlParameter.Optional, id3 = UrlParameter.Optional }
);
}
However, using this route the page no longer loads.
Does MVC Routing have some sort of CAP as to the amount of parameters it can map to? We also discovered that if we shrink the number of mapped parameters to id, id2, and id3 it will work however again with all overflow concatenated into id3.
Does anyone have any information around this?
Upvotes: 0
Views: 1386
Reputation: 1090
ASP.NET MCV has no limit on the number of parameters.
In your case
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Display_default",
"Display/{controller}/{action}/{id}/{id2}/{id3}/{id4}/{id5}/{*id6}",
new { action = "Index", id = UrlParameter.Optional , id2 = UrlParameter.Optional, id3 = UrlParameter.Optional }
);
}
Variable id is optional however id4 is mandatory. You have to add optional parameters into the end.
Like
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id5}/{id6}/{id}/{id2}/{id3}/{*id4}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, id2 = UrlParameter.Optional, id3 = UrlParameter.Optional, id4 = UrlParameter.Optional, id5 = UrlParameter.Optional , id6 = UrlParameter.Optional }
);
Or make all of parameters optional
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}/{id2}/{id3}/{id4}/{id5}/{*id6}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, id2 = UrlParameter.Optional, id3 = UrlParameter.Optional, id4 = UrlParameter.Optional, id5 = UrlParameter.Optional }
);
Upvotes: 1