我的布局文件中有以下内容:
@{
ViewBag.Title = "Default page title";
}
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
</head>
.....
在我看来,我有:
@{
ViewBag.Title = "Home";
Layout = "~/Views/Shared/_Layout.cshtml";
}
但是,页面标题显示为“默认页面标题”。
如何让页面标题显示为“主页”?如果我没有在 View 中为 ViewBag.Title
指定值,我只想显示“默认页面标题”。
最佳答案
换行:
ViewBag.Title = "Default page title";
到
ViewBag.Title = ViewBag.Title ?? "Default page title";
关于asp.net-mvc-3 - 在 MVC3 中创建默认站点页面标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9693286/