ASP.NET MVC 3剃须刀:包括头标记JavaScript文件 [英] ASP.NET MVC 3 Razor: Include JavaScript file in the head tag
本文介绍了ASP.NET MVC 3剃须刀:包括头标记JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找出正确的语法剃刀得到一个JavaScript文件为特定的* .cshtml是在头标记与所有其他包括_Layout.cshtml中定义的文件一起。
I'm trying to figure out the proper Razor syntax to get a JavaScript file for a particular *.cshtml to be in the head tag along with all the other include files that are defined in _Layout.cshtml.
推荐答案
您可以使用 <一个href=\"http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx\">Named第的。
You can use Named Sections.
_Layout.cshtml
<head>
<script type="text/javascript" src="@Url.Content("/Scripts/jquery-1.6.2.min.js")"></script>
@RenderSection("JavaScript", required: false)
</head>
_SomeView.cshtml
@section JavaScript
{
<script type="text/javascript" src="@Url.Content("/Scripts/SomeScript.js")"></script>
<script type="text/javascript" src="@Url.Content("/Scripts/AnotherScript.js")"></script>
}
这篇关于ASP.NET MVC 3剃须刀:包括头标记JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文