How do you handle a variable number of MVC routes?

I mark this intriguing bit in ASP.NET MVC:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

I would like to map {* pathInfo} to a route.

Sort of:

routes.MapRoute(
  "area/{*pathInfo}",
   "{controller}/{action}/{id}",parameters
   new { controller = "Area", action = "Index", id = ??? } 
);

but how to pass the variable "foo / bar / rab / oof" from mydomain.com/area/foo/bar/rab/oof? Either transferring the entire bit as a string, or as a collection will be fine with me.

Thanks!

+3
source share
1 answer

What version of MVC are you using? The route name should be the first MapRoute () parameter, as I recall in MCV Beta. Anyway, given your goal of capturing a path, I would do s / t like:

routes.MapRoute("AreaRoute", "Area/{*values}", new {controller = "Area", action = "Index"}       );

And in the Area controller:

// "value" argument is the string after Area/, i.e. "foo/bar/rab/oof" in your example
public string Index(string values)  
{  
  ...
}
+4
source

Source: https://habr.com/ru/post/1704257/


All Articles