Reputation: 5266
I have the following in my _Layout.cshtml:
<title>@ViewData["PageTitle"]</title>
I then have a Child Action that is called, and I want to be able to set change this value in that controller action.
Is this possible?
Upvotes: 1
Views: 1601
Reputation: 1038730
You could try using the parent context. In your _Layout.cshtml
:
<title>@ViewContext.ViewData["PageTitle"]</title>
and in your child action:
[ChildActionOnly]
public ActionResult Foo()
{
ControllerContext.ParentActionViewContext.ViewData["PageTitle"] = "foo";
return View();
}
Upvotes: 4