Reputation: 170549
I'm using @RenderPage
to reuse the code across two similar pages. Each of the two pages consists of just @RenderPage
:
@RenderPage("~/Views/PathToImplementation.cshtml", new { paramsListHere })
the code reused (inside PathToImplementation.cshtml
) uses ViewBag.Title
to set the page title:
ViewBag.Title = somethingUseful;
The problem is changing ViewBag.Title
from inside the reused code has no effect on the original page - nothing happens.
How do I change the title of a page from the code called by @RenderPage
?
Upvotes: 2
Views: 472
Reputation: 170549
Looks like when RenderPage
is used the ViewBag
is duplicated and the copy is passed into the page which RenderPage
renders and there's no way back. So the cleanest way I've found so far is passing a reference to the page that calls RenderPage
. Something like this:
//calling page
@RenderPage( PathToPage.cshtml, new { ParentPage = this } )
//PathToPage.cshtml
@{ WebViewPage parentPage = PageData["ParentPage"];
parentPage.ViewBag.Title = blahblahblhah;
}
Upvotes: 2