我正在开发一个 asp.net mvc 应用程序,我将此模板用于我的应用程序。对于 js 和 css 资源,我使用 URL.Content 辅助方法,但问题是模板引用的 css 资源仅在 home/index 操作中加载,当我转到其他操作时,浏览器控制台说它找不到资源。
这是我的 _layout.cshtml 中的内容:
<script src="@Url.Content("~/Scripts/jquery-1.8.3.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/js/config.js")"></script>
<script src="@Url.Content("~/js/skel.min.js")"></script>
<script src="@Url.Content("~/js/skel-panels.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<noscript>
<link rel="stylesheet" href="@Url.Content("~/css/skel-noscript.css")"/>
<link rel="stylesheet" href="@Url.Content("~/css/style.css")" />
<link rel="stylesheet" href="@Url.Content("~/css/style-desktop.css")" />
</noscript>
这是我在 chrome Element 选项卡中可以看到的内容:
<script src="/Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="/js/config.js"></script>
<script src="/js/skel.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style-desktop.css">
<script src="/js/skel-panels.min.js"></script>
<style type="text/css"></style>
<script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<noscript>
<link rel="stylesheet" href="/css/skel-noscript.css"/>
<link rel="stylesheet" href="/css/style.css" />
<link rel="stylesheet" href="/css/style-desktop.css" />
</noscript>
这是我从浏览器中的控制台得到的错误:
GET http:///myapp/test/css/style-desktop.css 404 (Not Found) skel.min.js:1
GET http://myapp/test/css/style.css 404 (Not Found) skel.min.js:1