Razor中的ViewBag.Title是什么? [英] What is ViewBag.Title in Razor?
问题描述
什么是ASP.NET MVC 4中的ViewBag.Title
?
What is ViewBag.Title
in ASP.NET MVC 4?
我有该查看文件:
@model IEnumerable<MvcMusicStore.Models.Genre>
@{
ViewBag.Title = "Store";
}
<h2>Index</h2>
而且我不知道更改ViewBag.Title
可能会完成什么.
and I do not know what changing ViewBag.Title
may accomplish.
推荐答案
来自 ASP.NET网站:
ViewBag是一个动态对象,这意味着您可以放置任何想要的东西 进去;在您放置ViewBag对象之前,它没有定义的属性 里面的东西.
ViewBag is a dynamic object, which means you can put whatever you want in to it; the ViewBag object has no defined properties until you put something inside it.
ViewBag.Title
属性只是一个字符串对象.在这种情况下,实际上是在视图中使用它定义 Title
属性.如果您要查看_Layout.cshtml
文件,则可能会看到类似以下内容的
The ViewBag.Title
property is simply a string object. In this case it's being used in the view to actually define the Title
property. If you were to look in your _Layout.cshtml
file you would likely see something like:
<title>@ViewBag.Title</title>
还记得在视图中定义属性的时间吗?最终呈现页面后,该属性最终出现在HTML标记中,如下所示:
Remember when the property was defined in the view? When the page is finally rendered, that property ends up in the HTML markup looking like:
<title>Store</title>
设置浏览器标题.
这篇关于Razor中的ViewBag.Title是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!