I'm using @Html.Glass().Editable(Model, x => x.MyProperty)
for some of our single-text / rich text fields. When I load the site with this code in the view everything looks fine. However, when I open the Experience Editor I see this error:
Value cannot be null. Parameter name: objectToSwitchTo.
at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)
at Sitecore.Common.Switcher`2.Enter(TValue objectToSwitchTo)
at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression`1 field, Expression`1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer)
I've seen a few other SO threads about this but no real solutions for me. I'm using a data source set on the rendering. I've stepped through the entire process and don't see any null attributes in my model after using GetDataSourceItem<MyClass>
. However, one thing I noticed is that my Sitecore ID field is all zeroes. I saw a different error prior to this, saying I needed to add a Sitecore ID field to my model, so I did. My code for the ID field is as follows:
[SitecoreId]
public virtual Guid Id { get; }
My Glass version is 4.5.0.4
which I believe is still pretty recent.
Id
field to{ get; set; }
, it works...[SitecoreId] public virtual Guid Id { get; private set; }
should do the trick.private set
first and it still didn't work. Regardless, it seems like I've found a solution to the problem - using{ get; set; }
.