views:

83

answers:

2

Hi,

I'm looking for some advice on storing views in a data-store (database, file, other) and display them based on routing data, all using ASP.NET MVC 2 and ASP.NET Routing.

For example, I'd like to be able to display different views based on the following route data:

/{country}/
/{country}/{area}

But in the same vein I'd like to display:

/{planet}/
/{planet}/{satellite}

All are based on strings, and the data isn't fixed. So based on the number of segments maybe, use that as the selection criteria into the data-store...additionally, I may not know the segments up front, so they'd all be dynamic.

I'm was hoping we could get a few different methods together here, as kind of a reference for all - I'm sure some methods won't suite everyone...

So, how would you do it?


Branislav Abadjimarinov suggested a Controller Factory which could be used to do the look-up and display the page dynamically. I like this idea, what do you think?

A: 

This Post could be really helpful for you.

Remember you always can add a new routing rule : )

Just like this

SDReyes
+1  A: 

There is no way for MVC to understand from this url's which route to choose. You have to make the routes more specific. For example:

/planet/{planet}/{satelite}

/country/{country}/{area}

You also have the option to define your own controller factory. The controller factory decides which controller to instantiate based on the route. So you can put some custom logic in it like - check if the {planet} parameter exist and if yes instantiate Planet controller else instantiate Countries controller.

Branislav Abadjimarinov
Ah, so a generic controller could be created by the controller factory to serve the request...I like, thanks!
Kieron
Went with the custom controller factory which worked just fine for us, thanks.
Kieron