Possible Duplicate:
Modifying MVC 3 ViewBag in a partial view does not persist to the _Layout.cshtml
I’m trying to set a pageTitle from a PartialView
Here is my code:
PartialView template:
@{
((WebViewPage)WebPageContext.Current.Page).ViewBag.Title = "Page title";
}
_Layout.cshtml:
<title> @ViewBag.Title</title>
How to do this?
That’s not something that a partial should do. It’s just not its responsibility to modify the parent view
ViewBag. And in addition to that it’s not possible. Quote from MSDN:You could always do the workarounds shown here but please don’t. Partials should not be setting any parent state. They should not know anything about the parent.