Value cannot be null Parameter name objectToSwitchTo - Glassmapper Rendering parameters
Page Editable Rendering Parameters
Problem:
We are on Sitecore 8.1 update 3 and using the latest release of Glassmapper (4.2.1.188). When we try to use @Editable it works for data source items. But not for rendering parameters.
in .cshtml we have below code:
var rp = GetRenderingParameters<IEditorialComponent>();
@Html.Glass().Editable(rp, x => x.Heading) @Editable(rp, x => x.Heading)
Both ways are not working, in page editor mode and getting below 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) in \Glass.Mapper.Sc\GlassHtml.cs:line 582
Rendering Parameters class:
[SitecoreType(TemplateId = "{templateId}")]
public partial interface IEditorialComponent : IGlassBase
{
[SitecoreField(FieldId = "FieldId")]
string Body { get; set; }
}
Solution:
Sitecore does not support making rendering parameters editable via the page editor in the same way as fields. You have to edit rendering parameters by using the rendering properties window.
Therefore Glass doesn't support this either.
I get to know about this by raising a question in StackOverflow link here
The model item passed into the dictionary is of type Sitecore Mvc Presentation RenderingModel, but this dictionary requires a model item of type xxx
You might have come to this page as you encoutered same error as mine. I am using Glassmapper as ORM for sitecore.
There are many reasons for this error. Below are couple of them.
- Make sure you are passing in right datsource template for your rendering. If your rendering is not expecting any datasource make sure u have datasource field empty on presentation.
- If you are in multi-lingual environment, make sure all the items needed by the rendering have this language version, Using language fallback helps in this
RECENT POSTS
POPULAR POSTS
CATEGORIES
- sitecore-unicorn
- sitecore-contacts
- sitecore-xdb
- sitecore-handling-500-errors
- sitecore-bug
- sitecore-media-library
- sitecore-content-editor
- sitecore-patch
- personal-opinions
- programming
- sitecore-error
- sitecore-usermanager
- sitecore-languge-settings
- sitecore-content-language
- microsoft-Bot-Framework
- Chatbot-Beginners
- ChatBot-Emulator
- botFramework
- FirstChatBot
- chatbot
- sitecore-customroutes
- sitecore-api
- sitecore-buckets
- sitecore-wildcards
- sitecore-layoutdetails
- sitecore-modals
- sitecore-client
- sitecore-deviceeditor
- sitecore-best-practises
- sitecore-templates
- sitecore
- sitecore-scheduling
- sitecore-autopublish
- sitecore-autopublish
- extension-method
- sitecore-multisite
- sitecore-events
- sitecore-publishing
- sitecore8.1
- Rendering Parameters
- GlassMapper
- Sitecore