I tried to use ViewBag in a Sitecore MVC view rendering to pass some data to its relevant layout rendering but it didn't work. In standard ASP.NET MVC you can do that, but is it possible to do the same in Sitecore also? If not, then how do you pass data?
Edit
to clarify my question, here is what I was trying to do: I have a layout rendering like this:
@using Sitecore.Mvc
@using Sitecore.Mvc.Analytics.Extensions
@using Sitecore.Mvc.Presentation
@model RenderingModel
@{
Layout = null;
}
<!doctype html>
<html>
<head>....</head>
<body>
@if (ViewBag.ShowNewsletterPopup == "display")
{
<!-- render proper html markup to show newsletter popup -->
}
else {
<!-- render regular html markup -->
}
<!-- some html markup here -->
@Html.Sitecore().Placeholder("widget")
<!-- some more html markup -->
And then, inside content placeholder goes a view rendering which has a code like this:
@using Sitecore.Mvc
@using Sitecore.Mvc.Presentation
@using Sitecore.Data.Items
@model RenderingModel
@{
ViewBag.ShowNewsletterPopup = Model.Rendering.Parameters["ShowNewsletterPopup"];
So, what I am trying to achieve is switching between two blocks of html markups depending on the settings of a view rendering which sits outside those blocks. Perhaps there is a better way to do this, but I am not sure. What I see is that the view rendering code gets compiled after layout rendering, so the code really never gets executed.
Sitecore.Context.Item["ShowNewsletterPopup]
in both layout and the rendering? Maybe you could also add a pipeline processor in `httpRequestBegin, search for this parameter and save the value somewhere to later use it in your layout, then you could get rid of inside-out renderings. – Kevin Brechbühl