我正在尝试访问部分视图中的视图中定义的 PageData。如果我将 PageData 作为模型传递给部分视图,我就可以访问它。我不喜欢这种方法,因为它不是视图的模型。部分视图将有自己的 PageData 实例。那么有没有办法访问Parent的ViewData呢?这是示例代码...查看代码
@{
ViewBag.Title = "Home Page";
PageData["MyName"] = "Sathi";
}
<h2>@ViewBag.Message</h2>
<h3>@WebPageContext.Current.Page.PageData.Count()</h3>
<h3>@PageData["MyName"]</h3>
<h3>@WebPageContext.Current.Page.PageData.Count()</h3>
@{ Html.RenderPartial("_Partial"); }
Parent view ends here
Run Code Online (Sandbox Code Playgroud)
部分查看代码
This is a partial view
<h3>@PageData["MyName"]</h3><-- Empty
<h3>@WebPageContext.Current.Page.PageData.Count()</h3>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1154 次 |
| 最近记录: |