I had previously been using TempData to set things like a "body css class", which then pages and partials could override.
I've now moved over to ViewData after realising that TempData uses sessions, however setting a ViewDataDictionary's value inside the partial basically gets ignored when it gets back up to the page - and never propagates up the layout hierarchy.
I've tried calling "RenderPartial" from inside my Page, and using the override which allows me to specify the ViewData to pass over:
Layout:
Page:
@{
var cssClass = (ViewData["something"] != null) ? ViewData["something"].ToString() : "";
}
<body class="@cssClass">
Page:
@{
ViewData["something"] = "blah";
Html.RenderPartial("MyPartial", ViewData)
}
Partial:
@{
ViewData["something"] += " blah";
}
When I debug inside my Layout, I can see that ViewData["something"] is "blah" - the partial didn't set it correctly.
When I was using TempData this would work ok. I don't really want to go back to using TempData because of ASP session locking and its effect on concurrent requests.
Has anybody got this to work before? Am I overlooking something?
Thanks