2

Working on an upgrade from Sitecore 8.2 to 9.2, I also upgraded glassmapper 4.3 to 5.6

In glass 5 also some changes in the controllers:

Glass 4:

public class MainVisualController : GlassController
{
    public ActionResult MainVisual()
    {
        var datasource = this.GetDataSourceItem<MainVisual>(false, true);
        var parameters = this.GetRenderingParameters<MainVisualRenderingParams>();

        var model = Mapper.Map<MainVisualJsonDto>(datasource).Map(parameters);

        return this.React(Constants.FrontendComponents.Sections.MainVisual, model);
    }
}

Glass 5:

public class MainVisualController : Controller
{
    private readonly IMvcContext mvcContext;

    public MainVisualController(IMvcContext mvcContext)
    {
        this.mvcContext = mvcContext;
    }

    public ActionResult MainVisual()
    {
        var datasource = this.mvcContext.GetDataSourceItem<MainVisual>();
        var parameters = this.mvcContext.GetRenderingParameters<MainVisualRenderingParams>();

        var model = Mapper.Map<MainVisualJsonDto>(datasource).Map(parameters);

        return this.React(Constants.FrontendComponents.Sections.MainVisual, model);
    }
}

Note that I use Controller (System.Web.Mvc.Controller) instead of GlassController, and added a constructor to inject IMvcContext.

The MainVisual model contains an Image field and a Title field. Everything works fine on Content Delivery, but in the CMS in Experience Editor, I noticed that the Title field and all other field on all components are not editable anymore.

Looking at this specific field datasource.Title, I see that on Sitecore 8.2 and Glass 4.3 it contains the edit control:

<input id='fld_47711AD1CF72485C8CE9396ADE6632D7_0C618E0645B548388776EB49D331C20D_nl-NL_1_e990f673e4e5419b9c9c124de93354b3_382' class='scFieldValue' name='fld_47711AD1CF72485C8CE9396ADE6632D7_0C618E0645B548388776EB49D331C20D_nl-NL_1_e990f673e4e5419b9c9c124de93354b3_382' type='hidden' value="Welcome to the website" /><span class="scChromeData">{"commands":[{"click":"chrome:common:edititem({command:\"webedit:open\"})","header":"Edit the related item","icon":"/temp/iconcache/office/16x16/cubes.png","disabledIcon":"/temp/cubes_disabled16x16.png","isDivider":false,"tooltip":"Edit the related item in the Content Editor.","type":"common"},{"click":"chrome:rendering:personalize({command:\"webedit:personalize\"})","header":"Personalize","icon":"/temp/iconcache/office/16x16/users_family.png","disabledIcon":"/temp/users_family_disabled16x16.png","isDivider":false,"tooltip":"Create or edit personalization for this component.","type":"sticky"}],"contextItemUri":"sitecore://master/{47711AD1-CF72-485C-8CE9-396ADE6632D7}?lang=nl-NL&ver=1","custom":{},"displayName":"Title","expandedDisplayName":null}</span><span id="fld_47711AD1CF72485C8CE9396ADE6632D7_0C618E0645B548388776EB49D331C20D_nl-NL_1_e990f673e4e5419b9c9c124de93354b3_382_edit" sc_parameters="prevent-line-break=true" contenteditable="true" class="scWebEditInput" scFieldType="single-line text" scDefaultText="[No text in field]">Welcome to the website</span>

But in Sitecore 9.2 with glass 5.6 using the experience editor, I only see the field value in datasource.Title: Welcome to the website

This results in components where nothing can be edited. What could be causing this? Reviewing the upgrade to V5 documentation does not give me any clue.

1

Please change requestValidationMode="4.0" to requestValidationMode="4.5" in web.config file. It was working for me.

| improve this answer | |
  • Unfortunately, this does not work for me. – Nico Lubbers Jun 14 at 21:52
0

I found the cause of the problem.

It was caused by myself during the upgrade of glassmapper. The views are rendered by React and therefore it is needed that the models already contain the rendered fields in experience editor mode.

By installing a higher version of the glassmapper nuget package the files App_Start\GlassMapperSc.cs and App_Start\GlassMapperScCustom.cs were reverted to the default. And in my GlassMapperScCustom a custom DataMapperFactory was added to the dependencyResolver. In that datamapper the GetFieldValue was overriden containing this piece of code:

    public override object GetFieldValue(
        string fieldValue,
        SitecoreFieldConfiguration config,
        SitecoreDataMappingContext context)
    {
        try
        {
            return FieldRenderer.Render(
                context.Item,
                config.FieldId.ToString(),
                "Cacheable=true&Cache_VaryByData=true");
        }
        catch (Exception ex)
        {
            this.logger.Error("Error getting field value.", ex);
        }

        return fieldValue;
    }

That was the reason that the models are already containing all the json needed for the frontend React code to render an editable field. It took me a while to figure out that the customization that was applied on glassmapper was undone during the upgrade.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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