相关疑难解决方法(0)

从视图或部分视图添加CSS或JavaScript文件到布局头

布局页面头:

<head>
    <link href="@Url.Content("~/Content/themes/base/Site.css")"
          rel="stylesheet" type="text/css" />
</head>
Run Code Online (Sandbox Code Playgroud)

应用程序需要的View(AnotherView):

<link href="@Url.Content("~/Content/themes/base/AnotherPage.css")"
      rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)

和AnotherView有一个局部视图(AnotherPartial)需要:

<link href="@Url.Content("~/Content/themes/base/AnotherPartial.css")"
      rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)

问题:我们如何这些CSS文件链接添加到Layouthead和AnotherPartial链接到Layout头

RenderSection不是一个好主意,因为AnotherPage可以有多个Partials.添加所有CSS到头部是没用的,因为它将动态更改(它取决于Anotherpages).

asp.net-mvc razor asp.net-mvc-3

171
推荐指数
6
解决办法
22万
查看次数

如何在视图中包含js文件.ASP.NET MVC 4

我想知道为什么我的js文件在我在视图中调用时工作:

@section Scripts {  
<script>   

    function myFunction() {
        alert("Hello1");
    }       

</script>
}
Run Code Online (Sandbox Code Playgroud)

但是当我打电话时它不起作用:

@section Scripts {

   <script type="text/javascript" src="~/Views/Home/script.js"></script>
   <script>   
         myFunction();
    </script>
}
Run Code Online (Sandbox Code Playgroud)

javascript asp.net-mvc-4

18
推荐指数
2
解决办法
6万
查看次数