4

I have a project with Glass.Mapper v4 and i have a simple model class like this:

    public class Separator
    {
        public virtual string Title { get; set; }
        public virtual string CssColorClass { get; set; }
    }

And a razor view like this:

@model ConexioFC.Models.Separator

This is the separator
<h2 class="@Model.CssColorClass">@Model.Title</h2>

From Sitecore i have this templates:

enter image description here

Then i have a View Rendering like this: This view rendering has a parameters template pointing to the template previously shown. enter image description here

Then i have on the control properties of the page:

enter image description here

The problem is that when i go to the page preview the Model.CssColorClass and Model.Title are blank.

2 Answers 2

3

First of all is not recommended to put content like Title in the rendering paramenters.

@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<ConexioFC.Models.Separator>

var parameters = GetRenderingParameters<ConexioFC.Models.RenderingParameters.Separator>();}

and you can to access parameters using @parameters.PropertyName

More informations you can find here:
http://www.glass.lu/Mapper/Sc/Tutorials/Tutorial23

https://stackoverflow.com/questions/29714169/inherit-model-and-rendering-parameters-both-in-sitecore-mvc-view-using-glass-map

4
  • What would be the NameofyourParametersTemplate?
    – Phoenix_uy
    Commented Feb 3, 2017 at 13:53
  • The template that contains your rendering parameters Commented Feb 3, 2017 at 13:55
  • So this is the best approach to use with Glass.Mapper v4? because i though that this was for Glass.Mapper v3.x and with Glass.Mapper v4 was more easy to do (without using the GetRenderingParameters) like here glass.lu/Mapper/Sc/Tutorials/Tutorial2.
    – Phoenix_uy
    Commented Feb 3, 2017 at 14:03
  • Link you send me now : is not for rendering params is for sitecore fields Commented Feb 3, 2017 at 14:04
0

That's because your rendering parameters aren't your viewmodel, the page item/datasource item is.

You can however get it as a viewmodel if you want, have a look at this blog post: https://visionsincode.wordpress.com/2016/08/26/map-your-rendering-parameters-to-your-glass-mapper-viewmodels-in-sitecore/

Or the default way of working with rendering parameters: http://www.glass.lu/mapper/sc/tutorials/tutorial23

@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<ConexioFC.Models.Separator>

@{ var parameters = GetRenderingParameters<ConexioFC.Models.RenderingParameters.Separator>();}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.