Search code examples
sitecoresitecore7glass-mappersitecore-mvcsitecore8

Inherit model and rendering parameters both in Sitecore MVC view using Glass Mapper


I am trying to access the rendering parameters for a particular view rendering, which also has the model bound to it, something like this:

@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<IPageBase>

I was reading the tutorial for the rendering parameters on glass.lu - http://www.glass.lu/Mapper/Sc/Tutorials/Tutorial23 - that I should be to inherit the parameters template the same way:

@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<INews_Rendering_Parameters>

But I can't bind both of them - so how is this done?


Solution

  • The GlassView class also exposes the GetRenderingParameters method, so you can use that in your Razor view to access the strongly typed rendering parameters:

    @inherits Glass.Mapper.Sc.Web.Mvc.GlassView<IPageBase>
    
    var parameters = GetRenderingParameters<INews_Rendering_Parameters>();
    

    then access your properties as normal, e.g. @Editable(model, x => x.Title) or @parameters.MyProperty

    It's mentioned in the tutorial at the end of Sitecore MVC but perhaps the example is not very clear.