【发布时间】:2016-01-05 16:05:58
【问题描述】:
我遇到了一个“奇怪”的问题。我的输出 html 标题元素创建换行符和空格。
<title>
Title | Brand name
</title>
我使用 MVC 2 并获得以下代码来生成我的标题元素
Site.Master
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server"></asp:ContentPlaceHolder></title>
页面 (aspx)
<asp:Content ContentPlaceHolderID="TitleContent" runat="server">
<%= Html.SeoTitle(Model.MetaTitle.Trim(), Html.DefaultTitle())%>
</asp:Content>
助手
public static string SeoTitle(this HtmlHelper helper, string title, string separator, bool siteNameLast, string fallbackTitle)
{
var siteName = SiteName(helper);
title = !string.IsNullOrEmpty(title) ? title : fallbackTitle;
if (string.IsNullOrEmpty(siteName))
return title;
title = title.TextToEntity();
title = siteNameLast ? string.Format("{0} {1} {2}", title, separator, siteName) : string.Format("{0} {1} {2}", siteName, separator, title);
return title;
}
我找不到任何与我为什么得到这个结果有关的东西。有什么想法吗?
编辑
应用答案将减少一个换行符,使输出如下所示。我可以在同一行吗?
<title>
title | brand name
</title>
【问题讨论】:
-
它们在 HTML 中被视为尾随空格,浏览器不会呈现它们。你为什么要关心他们?
标签: c# html asp.net-mvc