Cascading MVC controllers with CatchAll Routes

Posted by Richard on Stack Overflow See other posts from Stack Overflow or by Richard
Published on 2010-05-14T10:13:23Z Indexed on 2010/05/15 8:34 UTC
Read the original article Hit count: 162

Filed under:
|

Hi,

I have an MVC app which has its routes defined with the final route being a catch all route to a "PageController" for a database driven collection of pages. What I want to achieve is to be able to plugin to the app a second controller to the catch all route which the first controller passes on to if it does not find the url recieved in the database.

Effectively I want to queue up controllers with catch all actions:

public ActionResult PageCatchall(string url)
{
    var page = repository.Get<Page>(string url);
    if (page != null)
    {
        // Handle the request
       return View(page)
    }
    // Otherwise pass to a new controller

   ????
}

Anyone have any good ideas as to how to solve this? I have tried RedirectToAction but that requires that the next controller has a different route to the action. I have tried ActionInvoker but this failed to work the way I did it.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about c#