Set page title from PartialView

Possible duplicate:
Changing MVC 3 ViewBag in partial view is not saved in _Layout.cshtml

I am trying to set pageTitle from PartialView

Here is my code:

PartialView Template:

@{
    ((WebViewPage)WebPageContext.Current.Page).ViewBag.Title = "Page title";
}

_Layout.cshtml:

<title> @ViewBag.Title</title>

How to do it?

+1
source share
1 answer

This is not what partial should do. He simply does not have to change the parent view ViewBag. And in addition to this, this is not possible. Quote from MSDN :

, ViewDataDictionary, . . , , ViewData . .

, , , . - . .

+5

Source: https://habr.com/ru/post/1614438/


All Articles