MVC3 Routing: passing part of the route as a path parameter

Say I have an action like

public ActionResult TheAction(string path) { ... }

What I want to do is get a request, for example: www.myapp.com/controller/TheAction/path/to/content, pass the path "path / to / path" of the route as the path to action parameter.

I guess I would have to play with a regular route / request handler, but before putting on gloves with complication, I wanted to see if you had any other suggestions.

+3
source share
1 answer

Just register /{controller}/{action}/{*path}in your registration route.

This makes the last catch-all parameter, so it will contain the rest of the path as you wish.

, :

        routes.MapRoute(
            "HasCatchAllPath", 
            "{controller}/{action}/{*path}", 
            new { controller = "Home", action = "Index" }  
        );
+6

All Articles