开发者

Cascading MVC controllers with CatchAll Routes

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 cont开发者_高级运维roller has a different route to the action. I have tried ActionInvoker but this failed to work the way I did it.


While I would avoid complex routing like this one, I guess best thing to do is to use custom route constraint that uses cached list of pages to match correct route (have done that with success).

I'll leave exact implementation for You as an exercise. ;o)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜