Copied to clipboard

Flag this post as spam?

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


  • Damon 217 posts 287 karma points
    Sep 02, 2015 @ 14:25
    Damon
    0

    Question on hijacking routes

    Hi,

    when you hijack a route, instead of returning the original view, is it possible to return a different view if a parameter is passed into the extended RenderMvcController?

    Thanks a lot!

  • Marc Goodson 1451 posts 9716 karma points MVP 5x c-trib
    Sep 02, 2015 @ 16:16
    Marc Goodson
    4

    Hi Damon

    Yes, so if you are using CurrentTemplate

    return CurrentTemplate(model);
    

    This will return the View the original node is based on, but as this is MVC you can just return using View eg:

    return View("MyOtherView", model);
    

    so

    public ActionResult Index(RenderModel model, int SomeParameter = 1)
    {
        var customModel = new CustomModel(model.Content, CultureInfo.CurrentCulture);
     if (someParameter == 1){
         return View("MyOtherView", customModel);
    } else {
        return CurrentTemplate(customModel);
        }    
    }
    

    You can also cause an umbraco node to load an alternative template using ?altTemplate=templateAlias on the querystring

    and you can create an ActionResult that matches the template alias to hijack the alternative template route.

  • Damon 217 posts 287 karma points
    Sep 03, 2015 @ 08:44
    Damon
    0

    Excellent thanks!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies