Sukhjeevan
Sukhjeevan

Reputation: 3156

Error in controller rendering while using glass mapper

I have implemented controller rendering in sitecore 8.1 MVC. I am getting the following error in Index method:

ERROR: The given key was not present in the dictionary

Code:

{
var context = new SitecoreContext();
var Model = context.GetCurrentItem<BasePage>(); //Error comes here
return View(Model);

Did I miss any glass mapper file? Any suggestions?

Upvotes: 0

Views: 673

Answers (1)

Ben Golden
Ben Golden

Reputation: 1580

I have normally seen this error when Glass fails to find its context for the site. Often times it is because of an error in the site definition config. If the error isn't immediately evident please provide a more complete stack trace and your site definition config.

As a side-note. It is generally better to either inherit from GlassController and use its SitecoreContext property or inject an instance of ISitecoreContext into your constructor using SitecoreContext.GetFromHttpContext().

Upvotes: 0

Related Questions