views:

85

answers:

1

So imagine I'm building a Multi User Dungeon system using a MVC web application. To describe the areas the player can explore, the system can contain a number of Maps, which will consist of Rooms and Doors - where doors connect two Rooms. Consider the authoring part of the system. To create a Map is easy - I need URLs like:

/Author/Maps              (an index of my maps)
/Author/Maps/Create       (a new Map)
/Author/Maps/Detail/3     (show Map details)
/Author/Maps/Edit/3       (edit map details)

Using a Routing scheme: /Author/{controller}/{action}/{ID}

It's the URLs for the Rooms that I need help with. When creating a new Room, I need to know which Map I'm creating it for.

/Author/Rooms/CreateIn/[mapID] ?

And then for editing a room's details:

/Author/Rooms/Edit/[roomID]
/Author/Rooms/Detail/[roomID]

Would this routing scheme work? And should the view that lists all the Rooms for a Map be an "Index" action on the Rooms controller, with a MapID passed in, or a "Rooms" action on a Map controller?

Thanks.

+1  A: 

I don't know if this is best practice, but I would do it like this:

Add a new route: /Author/Maps/{mapID}/Rooms/{action}/{roomID}

Since this is a route that I would only expect to use for the RoomsController, I wouldn't have a {controller} parameter in that route. Just set the controller to "Rooms" in the route's default object.

Then all the actions in your RoomsController would know which map they're working with.

The default Index action for RoomsController could be a list of all the Rooms for the specified map.

The Create action would look like Create(int mapID) and the Details action would look like Details(int mapID, int roomID)

Edit: regarding invalid URLs with a mismatched mapID and roomID, you could just ignore the mapID, but I think the better process would be to validate that the specified mapID is correct and show an error message if it is not.

Dennis Palmer
Yes, that would work. It makes sense too because the hierarchy of the data matches the URL hierarchy. Does it matter that there is a possibility of invalid URLs - in that you could have a roomID that doesn't belong in the specified mapID? I guess one would have to get the correct map where the room ID is provided, regardless of what is in the URL.
GC
Brilliant, thanks Dennis.
GC