12

I'm looking for a routing option similar to the nested RESTFul routes functionality available through Rails. The SimplyRestful project on MvcContrib doesn't appear to be active any longer nor does it appear to be current with the 1.0 MVC release.

This is the uri scheme I'm looking for,

/Activity/10/Task/1/Edit or /Activity/10/Task/Edit/1

I simply haven't been able to get it to work and all the documentation I've run across describes the non-nested scenario. It doesn't seem like it'd be that difficult....

This is what I've been working with...

    routes.MapRoute(null,
        "Activity/{activityId}/Task/{action}/{id}", 
        new { controller = "Task", action = "Edit", activityId = "", id = "" });

1 Answer 1

13

Add a default value for activity:

routes.MapRoute(null,
    "Activity/{activityId}/Task/{action}/{id}/{activity}",
    new { 
        controller = "Task", 
        action = "Edit", 
        id = "",
        activityId = "", 
        activity = "" });

Remember also that this route will only pick up urls on the form

/Activity/10/Edit/1/theActivity

while your example

/Activity/10/Edit/1

will be picked up by the default route, setting the route values to

controller = "Activity"
action = "10"
id = "Edit/1"

Phil Haack's Routing Debugger for ASP.NET MVC is extremely useful for figuring out how to work these things...

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I just realized that I'd pasted that in on accident before posting it.
The routing debugger mentioned popped up a couple times on my reader, I totally forgot about it. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.