views:

213

answers:

1

I'm building an APS.net MVC 2 app, where I have a parent table and a child table.

I've got the controller, view and model built for the parent table, so I can Add, Edit, View Details and dete records from the parent table.

I using the following routing to do this:

routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Parent", action = "List", id = "" }  // Parameter defaults

This setup lets me use the following urls in my app:

To list all parent records: /Parent/List
To view details for a specific parent record: /Parent/Details/< ID>
To Edit a specifc parent record: /Parent/Edit/< ID>

etc

Now I have a child table for each parent record. What is the standard routing for this?

To list app child records for a specific parent: Parent/< ID>/Child/List
To view details for a specific child record: Child/Details/< ID>
To edit a specific child record: Child/Edit/< ID>

Does that look right? And how would I go about setting up the MapRoute?

+2  A: 

For the 2nd and 3rd items in your list you current route will be fine, that is if you have a child controller.

To list app child records for a specific parent: Parent/< ID>/Child/List 
To view details for a specific child record: Child/Details/< ID> 
To edit a specific child record: Child/Edit/< ID>

For the 1st item simply create a new route

routes.MapRoute(
 "ParentWithChild", 
 "{parent}/{id}/Child/List", 
 new { controller = "Child", action = "ChildList", id = "", parent=""} 

I am assuming you want to use the controller child and will create a new action method called ChildList

The signature would be like this

public ActionResult ChildList(string parent, string id)

Quick point if "Parent" is the word parent rather than a name then the route will be

 "Parent/{id}/Child/List",

and signature would be

public ActionResult ChildList(string id)
Rippo