元素'称号'出现过几次,XHTML验证警告在ASP.NET.MVC母版页 [英] Element 'title' occurs too few times, XHTML validation warning in ASP.NET.MVC master page

查看:217
本文介绍了元素'称号'出现过几次,XHTML验证警告在ASP.NET.MVC母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到下面的XHTML验证警告在我的ASP.NET MVC的母版页:

I am getting the following XHTML validation warning in my ASP.NET MVC master page:

验证(XHTML 1.0过渡):元素'标题'发生过几次

母版页标题标签包含在的ContentPlaceHolder头标记,如下面的code。在中的ContentPlaceHolder标题标签进行验证时,没有考虑到的,我不希望只是添加头标记另外一个,因为那时我将留下两个标题标签。

The title tag for the master page is included in the ContentPlaceHolder in the head tag as shown in the code below. The title tag in the ContentPlaceHolder is not taken into account when performing the validation, and I do not want to just add another one in the head tag because then I will be left with two title tags.

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <asp:ContentPlaceHolder ID="head" runat="server">
        <title></title>
    </asp:ContentPlaceHolder>
</head>

一个解决,我发现是使用以下技术中的头标记:

One work around that I have found is to use the following technique in the head tag:

<% if (false) { %>
    <title></title>
<% } %>

这是要解决此警告的最佳做法?我不添加多余的code只是通过验证警告,但我会接受它,如果没有更好的选择的一个巨大的风扇。

Is this the best practice to resolve this warning? I am not a huge fan of adding the excess code just to pass validation warnings but I will live with it if there is not a better alternative.

推荐答案

做到这一点,而不是:

<head>
    <title><asp:ContentPlaceHolder ID="title" runat="server">Default Page Title Here</asp:ContentPlaceHolder></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>
</head>

或者作为替代,从每一页programattically设置标题。

Or as an alternate, set the title programattically from each page.

这是怎么回事你的情况是,创建一个新的视图时,它会创建它覆盖在占位符默认内容为空的内容项目。如果从视图中删除空的内容块,默认的占位符的内容将被使用,但你不能设置视图中的内容。使用code上面可以覆盖从每个视图一个默认的标题和包括脚本等等头部相互独立的。

What's happening in your case is that when a new view is created, it creates empty content items which override the default content in the placeholders. If you remove the empty content blocks from the view, the default placeholder content will be used, but then you can't set the contents from the view. Using the code above you can override a default title from each view and include scripts, etc. in the head independently of each other.

这篇关于元素'称号'出现过几次,XHTML验证警告在ASP.NET.MVC母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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