views:

144

answers:

1

I note this intriguing bit in ASP.NET MVC:

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

I'd like to map {*pathInfo} into a route.

Something like:

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

but how do I pass in the variable "foo/bar/rab/oof" from mydomain.com/area/foo/bar/rab/oof? Either passing the entire bit as a string or as a collection would be fine with me.

Thanks!

+1  A: 

Which MVC version are you using? The route name should be the first parameter to MapRoute() as I remember in MCV Beta. Anyway, given your goal of capturing the 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)  
{  
  ...
}
Buu Nguyen
Thanks for the quick reply. I'm using RC2. I'll test this out and get back to you.
John Kaster
Once I made sure this pattern was registered BEFORE the default route pattern (ready about that elsewhere but completely forgot about it while trying this!) your solution worked perfectly. Thanks much.
John Kaster
I'm glad it helps.
Buu Nguyen
It did help, for /area/1 and /area/1/2 .. but once I tried /area/1/2/3 as my url pattern, all subsequent requests for that page (i.e., /Scripts/jquery.js) were ALSO being sent to my Area controller. I tried putting in an explicit pattern above this one, and it still happens. Any further ideas?
John Kaster
I figured it out right after asking. My script reference was "../../Scripts/foo.js". Once I did "/Scripts/foo.js" it started working again. There's an issue in the routing logic because the behavior varies with context, and shouldn't match Scripts/* for Area/* though.
John Kaster