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 288 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 2149 posts 14377 karma points MVP 9x c-trib
    Sep 02, 2015 @ 16:16
    Marc Goodson
    5

    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 288 karma points
    Sep 03, 2015 @ 08:44
    Damon
    0

    Excellent thanks!

Please Sign in or register to post replies

Write your reply to:

Draft