Glass.Mapper icon indicating copy to clipboard operation
Glass.Mapper copied to clipboard

A/B Test not working with View Rendering that uses sitecore model items and Html.Glass().Editable

Open LCZ86 opened this issue 4 years ago • 7 comments
trafficstars

Steps to reproduce (Glass Vanilla 5.8.172)

  1. Create a View Rendering
  2. Create a sitecore Model Item (/sitecore/layout/Models/)
  3. Add your GlassMapper Models's Namespace to the sitecore model item
  4. Assign the model to the view rendering
  5. Use @Html.Glass().Editable() in your view (Example @Html.Glass().Editable(Model, x => x.Text)
  6. Create a component Test with your new view rendering
  7. When you switch from A to B in the experience editor you will get the following error:

Value cannot be null. Parameter name: objectToSwitchTo

at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName) at Sitecore.Common.Switcher2.Enter(TValue objectToSwitchTo) at Sitecore.Data.Items.ContextItemSwitcher..ctor(Item item) at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression1 field, Expression`1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer) in D:\a\Glass.Mapper\Glass.Mapper\Source\Glass.Mapper.Sc\GlassHtml.cs:line 571

GlassIssue

LCZ86 avatar Jan 14 '21 17:01 LCZ86

Your properties are missing the Virtual keyword, can you add this and see if works.

mikeedwards83 avatar Jan 15 '21 16:01 mikeedwards83

hi

We have identified the issue and we are working on a fix.

mikeedwards83 avatar Jan 15 '21 17:01 mikeedwards83

Hello,

unfortunately I still have the problem with all languages except the default en

LCZ86 avatar Jan 20 '21 17:01 LCZ86

You need to make sure you model also contains properties for Langauge and Version

public virtual Language Language{get;set;}

public virtual int Version{get;set;}

mikeedwards83 avatar Jan 21 '21 08:01 mikeedwards83

Unfortunately I am still able to repoduce. Could you please try it with any other language then en? This is my model:

   public class TextImageIndexView
  {
    [SitecoreId]
    public virtual Guid Id { get; protected set; }
    [SitecoreField("1A22E54A-8367-4714-BFA0-720B95148B41")]
    public virtual string TextImageText { get; set; }
    [SitecoreField("C9680286-A269-431D-82F2-7D1DFEE67EDC")]
    public virtual Glass.Mapper.Sc.Fields.Image TextImageImage { get; set; }

    [SitecoreInfo(SitecoreInfoType.Language)]
    public virtual Language Language { get; set; }

    [SitecoreInfo(SitecoreInfoType.Version)]
    public virtual int Version { get; set; }
  }

LCZ86 avatar Feb 02 '21 16:02 LCZ86

Any update on this? I am getting the same error. I tried using virtual for all properties but still the same error.

yeshwanth-t avatar Dec 15 '21 13:12 yeshwanth-t

I am wondering if it is related to this https://github.com/mikeedwards83/Glass.Mapper/issues/442

mikeedwards83 avatar Dec 16 '21 22:12 mikeedwards83