在ASP.NET MVC2的主模板中添加标题前缀 [英] Adding a Title Prefix in ASP.NET MVC2's Master's Template

查看:44
本文介绍了在ASP.NET MVC2的主模板中添加标题前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似以下的内容


I''ve got something like the following


<head id="Header" runat="server">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico"/><meta name="robots" content="index, follow" />
    <title>My Company Name :: <asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    ...



我有一个ContentPlaceHolder作为标题,但是由于整个头部都设置为runat ="server",因此它替换了整个标题.有没有一种方法可以在ASP.NET/MVC2的主模板中放入标题前缀?



I have a ContentPlaceHolder for the title, but since the entire head is set to runat="server", it replaced the entire title. Is there a way to put in a title prefix in ASP.NET/MVC2''s master templates?

推荐答案

嘿,

如果您不介意使用一些jQuery,这是超级容易的事情-不管怎么说,它几乎已经融入了MVC2.

在关闭<body></body>标记之前,将其放在主页的底部.

Hey there,

This is super easy to do if you don''t mind using a bit of jQuery - which is all but baked into MVC2 anyways.

Throw this in at the bottom of your master page before your closing <body></body> tag.

<script type="text/javascript">


(function(){ document.title ='您的公司::'+ document.title; }); < /script >
(function () { document.title = 'your company :: ' + document.title; }); </script>



请注意,您也可以使用直接JS,我仅将jQuery用于"onready"处理程序支持. document.title只是JS.

干杯.



Note that you can use straight JS too, I''m only using jQuery for the ''on ready'' handler support. document.title is just JS.

Cheers.


这篇关于在ASP.NET MVC2的主模板中添加标题前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆