我下载了一个完整的ASP。 NET MVC应用程序,但当我尝试在Razor视图中更改页面标题时,我得到默认值+ MyNewTitle 。
我尝试在以下内容中更改页面标题:
Layout.Title = "_test";
Model.Title = "_test";
但我得到了: SiteName - _test
这是Layout.cshtml的开头
@functions {
// To support the layout classifaction below. Implementing as a razor function because we can, could otherwise be a Func<string[], string, string> in the code block following.
string CalcuClassify(string[] zoneNames, string classNamePrefix)
{
var zoneCounter = 0;
var zoneNumsFilled = string.Join("", zoneNames.Select(zoneName => { ++zoneCounter; return Model[zoneName] != null ? zoneCounter.ToString() : ""; }).ToArray());
return HasText(zoneNumsFilled) ? classNamePrefix + zoneNumsFilled : "";
}
}
@{
//Layout.Title = "test";
//Model.Title = "TEST";
/* Global includes for the theme
***************************************************************/
Script.Require("jQuery").AtHead();
Style.Include("site.css");
Style.Include("styles.css");
Script.Require("jQuery");
Script.Include("scripts.js");
RegisterLink(new Orchard.UI.Resources.LinkEntry
{
Rel = "stylesheet",
Type = "text/css",
Href = "http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,300italic,400italic,500italic,700italic&subset=latin,cyrillic-ext,greek-ext,greek,latin-ext,cyrillic"
});
RegisterLink(new Orchard.UI.Resources.LinkEntry
{
Rel = "stylesheet",
Type = "text/css",
Href = "http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic"
});
/* Some useful shortcuts or settings
***************************************************************/
Func<dynamic, dynamic> Zone = x => Display(x); // Zone as an alias for Display to help make it obvious when we're displaying zones
/* Layout classification based on filled zones
***************************************************************/
//Add classes to the wrapper div to toggle aside widget zones on and off
var asideClass = CalcuClassify(new[] { "AsideFirst", "AsideSecond" }, "aside-"); // for aside-1, aside-2 or aside-12 if any of the aside zones are filled
if (HasText(asideClass))
{
Model.Classes.Add(asideClass);
}
//Add classes to the wrapper div to toggle tripel widget zones on and off
var tripelClass = CalcuClassify(new[] { "TripelFirst", "TripelSecond", "TripelThird" }, "tripel-"); // for tripel-1, triple-2, etc. if any of the tripel zones are filled
if (HasText(tripelClass))
{
Model.Classes.Add(tripelClass);
}
//Add classes to the wrapper div to toggle quad widget zones on and off
var footerQuadClass = CalcuClassify(new[] { "FooterQuadFirst", "FooterQuadSecond", "FooterQuadThird", "FooterQuadFourth" }, "split-"); // for quad-1, quad-2, etc. if any of the quad zones are filled
if (HasText(footerQuadClass))
{
Model.Classes.Add(footerQuadClass);
}
/* Inserting some ad hoc shapes
***************************************************************/
WorkContext.Layout.Header.Add(New.Branding(), "5"); // Site name and link to the home page
WorkContext.Layout.Footer.Add(New.BadgeOfHonor(), "5"); // Powered by Orchard
//WorkContext.Layout.Footer.Add(New.User(), "10"); // Login and dashboard links
/* Last bit of code to prep the layout wrapper
***************************************************************/
Model.Id = "layout-wrapper";
var tag = Tag(Model, "div"); // using Tag so the layout div gets the classes, id and other attributes added to the Model
}
@tag.StartElement
答案 0 :(得分:2)
它不在Layout.cshtml中,而是在Document.cshtml中。在那里你会找到顶部的某个地方:
<!DOCTYPE html>
<html lang="@WorkContext.CurrentCulture">
<head>
<meta charset="utf-8" />
<meta name="robots" content="index, follow, archive" />
<!-- See the construction of the title here -->
<title>@Html.Title(title, siteName)</title>
// other stuff
</head>
此文件可在Orchard.Core / Shapes / Views / Document.cshtml
中找到您可能不希望在此文档中更改此内容,因为您正在更改核心文件(这是一种不好的做法,例如,如果您更新Orchard,文件将再次被覆盖)。
幸运的是,Orchard是一个了不起的CMS,它允许您自定义所有内容,而无需更改核心。
我建议,如果您还没有这样做,要创建一个基于TheThemeMachine主题的新主题,请将Document.cshtml复制到其views目录并根据需要更改它。
Here您可以找到如何创建自定义主题