Set a page title from a PartialView
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Modifying MVC 3 ViewBag in a partial view does not persist to the _Layout.cshtml
我正试图从一个部分视图中设置一个页面标题
这是我的代码:
局部视图模板:
1 2 3 | @{ ((WebViewPage)WebPageContext.Current.Page).ViewBag.Title ="Page title"; } |
SytLM.CsHTML:
1 | @ViewBag.Title |
如何做到这一点?
这不是部分人应该做的事。修改父视图
When a partial view is instantiated, it gets its own copy of the
ViewDataDictionary object that is available to the parent view. The
partial view therefore has access to the data of the parent view.
However, if the partial view updates the data, those updates affect
only the partial view's ViewData object. The parent view's data is not
changed.
您可以始终执行此处显示的解决方法,但请不要执行。部分不应设置任何父状态。他们不应该知道关于父母的任何事情。