追加到默认的标题在asp.net母版 [英] Appending to default title in asp.net masterpage
问题描述
我使用MVC为标题添加到母版与内容占位符。默认的MVC母版模板使用以下code:
I am using the MVC to add a title to the masterpage with a content place holder. The default MVC masterpage template uses the following code:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server"/></title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
</head>
当我尝试默认的文本添加到内容持有人的面前,它不会显示在最终渲染页面的文本。我试图让该页面显示与附加的ContentPlaceHolder文本的默认标题。
When I try to add defaulted text to the front of the content holder, it doesn't show the text in the final rendered page. I am trying to get the page to show a default title with appended contentplaceholder text.
例如:
(默认文本)(的ContentPlaceHolder文本)
我的页面 - 关于我们
Example:
(Default Text) (ContentPlaceHolder Text)
My Page - About Us
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Page - <asp:ContentPlaceHolder ID="TitleContent" runat="server"/></title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
</head>
我要寻找一种方式来做到这一点,而不必使用code后面。任何想法?
I am looking for a way to accomplish this without having to use code behind. Any ideas?
推荐答案
进一步细算,菲尔哈克居然贴出了一篇文章这是我的问题的解决方案。它可以在 Haacked 被发现。
After looking further, Phil Haack actually posted an article which was a solution to my question. It can be found at Haacked.
在总结,他说,这是在头部呈现的一切都呈现为一个控件,上面我的问题的解决方法是把一个asp文字控制在标题里有它正确生成的文本。
In summary he said that everything that is rendered in the head is rendered as a control, and the fix for my question above is to put an asp literal control in the title to have it correctly generate the text.
<%@ Master ... %>
<html>
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="titleContent" runat="server" />
<asp:LiteralControl runat="server" Text=" - MySite" />
</title>
</head>
...
这篇关于追加到默认的标题在asp.net母版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!