4

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>

Project soultion

2
  • 1
    in asp.net 5/mvc 6 the new correct way to manage client side dependencies is using npm bower gulp and grunt, not nuget. I recommend create a new web project in vs2015 to see how it sets up jquery see also docs.asp.net/en/latest/client-side/index.html Commented Oct 4, 2015 at 16:56
  • Cheers, makes sense. Got it working there. Commented Oct 4, 2015 at 17:26

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.