ASP.NET MVC 3中的ViewBag.Title与Page.Title [英] ViewBag.Title vs. Page.Title in ASP.NET MVC 3
本文介绍了ASP.NET MVC 3中的ViewBag.Title与Page.Title的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么有时@ViewBag.Title
包含正确的页面标题,而@Page.Title
为null?我们正在调试我们的视图/布局代码,我们注意到了这种差异.
Why sometimes @ViewBag.Title
contains the right page title while @Page.Title
is null? We are debugging our View/Layout code and we noticed this difference.
谢谢.
推荐答案
正确使用的是ViewBag.Title
,因为它是在View
的ViewBag
属性的上下文中,而Page.Title
是来自asp.net网络表单.这就是Page.Title
为空,没有上下文的原因.
The correct is using ViewBag.Title
, because it is on the context of your ViewBag
property of your View
while Page.Title
is something that comes from asp.net webforms. That is the reason why Page.Title
is null, there is no context for it.
这篇关于ASP.NET MVC 3中的ViewBag.Title与Page.Title的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文