我下载了一个完整的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发布于 2015-07-23 07:37:30
它不是在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/View/Document.cshtml中找到。
您可能不想在本文档中更改这一点,因为随后要更改核心文件(这是一种不好的做法,例如,如果您更新Orchard,文件将再次被覆盖)。
幸运的是,Orchard是一个了不起的CMS,它允许您定制一切,而不改变核心。
如果您还没有这样做,我建议根据TheThemeMachine主题创建一个新主题,将Document.cshtml复制到它的视图目录中,并根据您的需要对其进行更改。
这里您可以找到如何创建自定义主题
https://stackoverflow.com/questions/31578801
复制相似问题