Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve Temple 63 posts 324 karma points MVP 3x c-trib
    Jan 07, 2014 @ 16:22
    Steve Temple
    1

    Hijack MVC route with additional parameters

    We're moving all business logic for a site into MVC controllers to make it testable. So we've added a set of controllers to deal with certain pages on the site with complex functionality.

    Using search as an example we'd like to pass additional parameters along with the RenderModel into a hijacked route. Like so:

    public ActionResult Index(RenderModel model, int? page) {
    

    However as this won't override the RenderMvcController's index method it causes an error 'Ambiguous match found' as there are two matching actions for Index.

    Is there a way of doing this (I could do Request.Querystring["page"] inside the action but that makes it difficult to test) or should I use a different type of controller with a custom route?

  • Eric Fredin 2 posts 22 karma points
    Jan 07, 2014 @ 19:40
    Eric Fredin
    0

    We ended up using child actions any time custom models were required.  http://our.umbraco.org/documentation/Reference/Templating/Mvc/child-actions.

  • Tim Brooks 27 posts 79 karma points
    Aug 22, 2014 @ 01:14
    Tim Brooks
    5

    I ran into the same issue and I noticed if you use the template name instead of overriding the Index action it works fine. 

     

    public ActionResult Product(RenderModel model, int? productId)

    {

    ...

    }

  • alimac 182 posts 371 karma points
    Feb 09, 2015 @ 17:57
    alimac
    0

    Thanks, Tim.. you saved me a lot of hassle!

Please Sign in or register to post replies

Write your reply to:

Draft