0

I have a legacy MVC action I'm trying to enhance for some limited number of cases. The solution I'm working on uses rendering parameters to impact the behavior of the control. To demonstrate the concept, I began with adding parameters to one of the rendering in question. Note: I'd prefer to do this without a rendering template, opting instead for the generic "additional parameters" fields on the rendering: [1]: https://i.stack.imgur.com/yPhWs.png

In my controller action, I attempt to read those parameters:

string testValue = RenderingContext.Current.Rendering.Parameters["TestValue"];
if (!testValue.IsNullOrEmpty())
{
  // Do some things with the value
}

However, according the the debugger, RenderingContext.Current.Rendering.Parameters is an empty collection in the controller-action.

Is it required that I use a Rendering parameters template? Is there some setting I need to touch to pass generic rendering params to the context?

Updated with a bit more investigation based on the comments:

In RenderingContext.Current.Rendering. I get an ID I can-not match (that changes on subsequent executions). The same context lists the deviceID and LayoutID as {00000000-0000-0000-0000-000000000000}, which doesn't seem correct.
I checked renderings using Sitecore.Context.Item.Visualization.GetRenderings(Sitecore.Context.Device, false), and it did contain the rendering I expected.

In my case, I know the control will only be included once, so I was able to resolve the correct settings looking for the ID of the rendering

ID contentDetailRenderingId = new ID("{B852FF27-F4E5-4E70-85B7-CB60A860F59F}");
RenderingReference[] renderings = Sitecore.Context.Item.Visualization.GetRenderings(Sitecore.Context.Device, false);
RenderingReference rendering = renderings.FirstOrDefault(x=>x.RenderingID == contentDetailRenderingId);

However, I'd have greatly preferred to match to something from the context rather than a constant-guid.
I suspect my specific issue may have to do with device resolution, and I haven't been able to resolve that yet. That said, I'm still looking for anything in the RenderingContext I can use to properly ID the rendering configuration in the presentation details.

  • If you debug it, is the Rendering ID the rendering you expect. This is one of the simplest things to do in Sitecore. Something simple must be a little off. – Chris Auer Jul 22 at 21:17
  • It's not a requirement to use the Rendering Parameters template, but I would say it's a better practice to do so, since it's easier for the Content Editor. If you leave it like it is, you could suffer from situations where a content editor miss-types the name of a parameter, and then the expected functionality doesn't work as expected. – Dylan Young Jul 23 at 0:14
  • Make sure you've published your content and that workflow isn't blocking the item from publishing. Rendering Parameters are saved to the Rendering information on your Context Item and not to the Datasource Item, so make sure your page is published. – Dylan Young Jul 23 at 0:24
  • Your first screenshot. Is that from the properties of the rendering in presentation details, or is that from the rendering definition item? – Mark Cassidy Jul 23 at 13:32
  • Presentation details (Control Properties from the Device Editor from the Layout Details modal). – GoetzOnline Jul 23 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.