ASP.NET MVC 3 Razor:在 head 标记中包含 JavaScript 文件 [英] ASP.NET MVC 3 Razor: Include JavaScript file in the head tag

查看:42
本文介绍了ASP.NET MVC 3 Razor:在 head 标记中包含 JavaScript 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出正确的 Razor 语法,以获取特定 *.cshtml 的 JavaScript 文件以及 _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.

推荐答案

你可以使用命名部分.

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 Razor:在 head 标记中包含 JavaScript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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