I am upgrading Glapp Mapper to V5. I see that the GlassView is deprecated and instead we have to use @Html.Glass().
In V4, my code has something like @Editable(Model, x=>x.BackGroundColor)
So I changed my code to something like @Html.Glass().Editable(Model, x=>x.BackGroundColor)
.
When I open Experience editor, This piece of code was throwing an error.
Failed item resolve - You cannot save a class that does not contain a property that represents the item ID. Ensure that at least one property has been marked to contain the Sitecore ID. Type: <NameOfMyClass>
.
After looking at the below link,
Glassmapper | Cannot save a class that does not contain a property that represents the item ID
I have added an ID to my model
[SitecoreId]
public virtual Guid Id { get; set;}
Now the above error went away, instead got a new error
Value cannot be null. Parameter name: objectToSwitchTo.
I saw that this question was asked in the past as in below link
Glass Error opening Experience Editor (ObjectToSwitchTo)
It already explains that if we have set
method with virtual
keyword, it should work. But in my case I already have those implemented and still having the null error.
I also tried assigning a value to Id something like id = Guid.NewGuid(); which has generated a new GUID. but nothing seems to work. Any thoughts?
Here is my Model
public class TestViewModel
{
#region Master Properties
public FundViewModel FundVM { get; set; }
public BaseViewModel BaseVM { get; set; }
[SitecoreId]
public virtual Guid Id { get; set; }
#endregion
public virtual SitecoreFields Fields { get; set; }
public class SitecoreFields
{
public virtual string Title { get; set; }
public virtual string BackgroundColor { get; set; }
}
}
public virtual Guid Id { get; set; }
intoSitecoreFields
and tryValue cannot be null. Parameter name: objectToSwitchTo
error.