Copied to clipboard

Flag this post as spam?

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


  • Phil Whittaker 63 posts 267 karma points MVP 3x c-trib
    Apr 09, 2016 @ 08:13
    Phil Whittaker
    0

    Generic UmbracoViewPage, Custom Models and route hijacking

    I am trying to combining the generic version of UmbracoViewPage, custom models and route hijacking but the model returned doesn't contain my bespoke properties. My controller action is

        public override ActionResult Index(RenderModel model)
        {
    
            var newModel = new RenderNewModel(model.Content);
            newModel.test = 'test';
    
            return CurrentTemplate(newModel);
        }
    

    When I inherit from UmbracoViewPage in the view the RenderNewModel is available but when I use the generic version the model is RenderModel

    How can I can make this work?

  • Marc Goodson 2148 posts 14353 karma points MVP 8x c-trib
    Apr 11, 2016 @ 21:41
    Marc Goodson
    0

    Hi Phil

    The view/template that you are using with your hijacked route and your custom model, needs to inherit:

    @inherits UmbracoViewPage<RenderNewModel>
    

    this tells your view about the existence of your custom model, and so makes your custom properties available; since your custom model inherits from RenderModel, then it also has all the usual model properties available... eg .Name, .Id etc

    The UmbracoViewPage bit ensures you have access to all those nice @Umbraco helpers within your view...

Please Sign in or register to post replies

Write your reply to:

Draft