gpt4 book ai didi

asp.net-mvc - MVC3 - 'Element ' 链接“无法嵌套在元素 'link' 内” - 尝试添加页面特定的 CSS

转载 作者:行者123 更新时间:2023-12-01 16:50:45 25 4
gpt4 key购买 nike

这样我就有了一个布局页面

<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<link href="@Url.Content("~/content/main_layout.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/content/menu.css")" rel="stylesheet" type="text/css" />
@RenderSection("JS", required:false)
@RenderSection("CSS", required:false)
</head>
<body>
@RenderBody()
</body>
</html>

然后是这样的 View

@{
ViewBag.Title = "Home";
Layout = "~/views/shared/_layout.cshtml";
}
@using RS.Common.HtmlHelpers;
@section JS
{
<script src="@Url.Content("~/scripts/fue.js")" type="text/javascript"></script>
<script src="@Url.Content("~/scripts/jquery.flexslider-min.js")" type="text/javascript"></script>
}
@section CSS
{
<link href="@Url.Content("~/content/hp.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/content/hp_form.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/content/flexslider.css")" rel="stylesheet" type="text/css" />
}

<h4>Test!</h4>

页面加载正常,正如我所期望的那样。但是,我收到 3 条警告:

Validation (XHTML 1.0 Transitional): Element 'link' cannot be nested within element 'link'

此错误针对 View 上 CSS 部分中的每个 标记。

在这个阶段这确实是一个烦恼,但我想知道这个错误的原因(以及解决方案)可能是什么?

最佳答案

您已指定 HTML5 DOCTYPE,但仍尝试验证为 XHTML 1.0 Transitional。我想最终呈现的 HTML 看起来像这样:

<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<script src="/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<link href="/content/main_layout.css" rel="stylesheet" type="text/css" />
<link href="/content/menu.css" rel="stylesheet" type="text/css" />

<script src="/scripts/fue.js" type="text/javascript"></script>
<script src="/scripts/jquery.flexslider-min.js" type="text/javascript"></script>

<link href="/content/hp.css" rel="stylesheet" type="text/css" />
<link href="/content/hp_form.css" rel="stylesheet" type="text/css" />
<link href="/content/flexslider.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h4>Test!</h4>
</body>
</html>

您可能希望反转布局中两个 RenderSection 的顺序,以便将链接和脚本分组在一起。或者您也可以考虑将脚本声明移至页面末尾:

像这样:

<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/content/main_layout.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/content/menu.css")" rel="stylesheet" type="text/css" />
@RenderSection("CSS", required:false)
</head>
<body>
@RenderBody()

<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
@RenderSection("JS", required:false)
</body>
</html>

关于asp.net-mvc - MVC3 - 'Element ' 链接“无法嵌套在元素 'link' 内” - 尝试添加页面特定的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10434120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com