使用时,页面标题不会改变@RenderPage [英] Page title not changed when using @RenderPage

查看:126
本文介绍了使用时,页面标题不会改变@RenderPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 @RenderPage 来重复使用跨两个相似的网页的code。每两页的由刚 @RenderPage

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 })

重用code(在 PathToImplementation.cshtml )使用 ViewBag.Title 来设置页面标题

ViewBag.Title = somethingUseful;

问题是从重用code内改变 ViewBag.Title 具有原始页面上没有任何影响 - 什么也没有发生

The problem is changing ViewBag.Title from inside the reused code has no effect on the original page - nothing happens.

我如何改变从名为code页面的标题由 @RenderPage

How do I change the title of a page from the code called by @RenderPage?

推荐答案

看起来当使用 RenderPage ViewBag 被复制和复制传递到该 RenderPage 渲染,有没有办法恢复了该页。所以到目前为止,我已经找到了干净的方式传递引用调用 RenderPage 页。事情是这样的:

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;      
}

这篇关于使用时,页面标题不会改变@RenderPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆