简体   繁体   English

MVC 6在通过Nuget添加后引用Jquery

[英]MVC 6 reference Jquery after adding via Nuget

I created a new MVC 6 project, empty template. 我创建了一个新的MVC 6项目,空模板。 added JQuery via NuGet. 通过NuGet添加了JQuery。 How do you reference it then in your _Layout file or wherever you want to use it. 如何在_Layout文件中或您想要使用它的任何地方引用它。 I dont have a script folder with Jquery in there. 我没有Jquery的脚本文件夹。

<head>
<meta name="viewport" content="width=device-width" />
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="~/css/site.css" />
<script src=""></script> -- HERE

<title>@ViewBag.Title</title>
</head>
<body>
<div>
    @RenderBody()
</div>
@RenderSection("scripts", required: false)
</body>
</html>

项目灵魂

Remove the package from Nuget and add via bower. 从Nuget中取出包裹并通过凉亭添加。 If you have created a new MVC 6 empty project. 如果您已创建一个新的MVC 6空项目。 you will need to add a bower.json file and then add the Jquery dependency 您将需要添加bower.json文件,然后添加Jquery依赖项

{
  "name": "ASP.NET",
  "private": true,
  "dependencies": {
    "jquery": "2.1.4"
 }
}

Then in your layout add the reference 然后在您的布局中添加引用

<script src="~/lib/jquery/dist/jquery.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM