简体   繁体   中英

MVC 6 reference Jquery after adding via Nuget

I created a new MVC 6 project, empty template. added JQuery via NuGet. How do you reference it then in your _Layout file or wherever you want to use it. I dont have a script folder with Jquery in there.

<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. If you have created a new MVC 6 empty project. you will need to add a bower.json file and then add the Jquery dependency

{
  "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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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