Today I was working on Sitecore Glass Mapping framework for my Sitecore MVC project. I’ve installed Glass Mapper from nuget and configured it for Sitecore MVC project. For more information on the Glass.Sitecore.Mapper visit the official website. Thanks Mike and Tom for this great framework. Below are the few details about my development environment:
Below is the implementation of Model class:
Comments and suggestions are most welcome. Happy coding!
- MVC Version: 4Sitecore Version: 7.0
- Glass.Mapper version: 3.0.10.23
- Glass.Mapper.Sc version: 3.2.0.39
- Glass.Mapper.Sc.Mvc version: 3.2.0.35
- Glass.Mapper.Sc.Razor version: 3.0.9.13
Below is the implementation of Model class:
using Glass.Mapper.Sc.Configuration.Attributes; using SitecoreRamblings.Service.Interface; namespace SitecoreRamblings.Models { [SitecoreType(AutoMap = true)] public class NewsModel { private readonly INewsService _service; public virtual string Title { get; set; } public virtual string Body { get; set; } public virtual string Abstract { get; set; } public NewsModel(INewsService service) { _service = service; } } }After investigation; I’ve realized that I forgot [my stupidity on peak :( ] to add an additional property in NewsModel class to represent the Sitecore ID. I’ve added below property in NewsModel class:
[SitecoreId] public virtual Guid Id { get; set; }Sitecore ID is required to allow Glass.Mapper to link your model to the actual Sitecore item in Page Edit mMode. After building solution, I was no longer getting error in Page Editor Mode.
Comments and suggestions are most welcome. Happy coding!
0 comments :
Post a Comment