I'm rewriting a website project with ASP.Net MVC 4 and I find it difficult to setup the right routes. The url structure is not RESTful or following a controller/action pattern - the pages have the following structure of slugs. All slugs are saved in the database.
/country
/country/carmake
/country/carmake/carmodel
/custom-landing-page-slug
/custom-landing-page-slug/subpage
Example:
/italy
/italy/ferrari
/italy/ferrari/360
/history-of-ferrari
/history-of-ferrari/enzo
Since Country
, Car Make
and Car Model
are different models/entities, I would like to have something like a CountriesController, CarMakesController and CarModelsController where I can handle the differing logic and render the appropriate views from. Furthermore, I have the custom landing pages which can have slugs containing one or more slashes.
My first attempt was to have a catch-all PagesController
which would look up the slug in the database and call the appropriate controller based on the page type (eg. CarMakesController
), which would then perform some logics and render the view. However, I never succeed to "call" the other controller and render the appropriate view - and it didn't feel right.
Can anyone point me in the right direction here? Thanks!
EDIT: To clarify: I do not want a redirect - I want to delegate the request to a different controller for handling logic and rendering a view, depending on the type of content (Country
, CarMake
etc.).