6

I downloaded jQuery in Visual Studio 2017 using Install-Package bootstrap -Version 4.1.1
Now I have a dependency which includes jQuery 3.3.1, but when I move to my script file, I can´t access jQuery and I don't get IntelliSense for jQuery when I enter $.
Is there some reference I must enter, in order to use jQuery in my script file?

enter image description here

Rohit Verma
  • 3,657
  • 7
  • 37
  • 75
clem995
  • 319
  • 2
  • 16
  • I'd suggest you have a look at [How jQuery Works](http://learn.jquery.com/about-jquery/how-jquery-works/) because it's too broad a topic to get a tutorial here. – Filburt Jul 04 '18 at 11:53
  • And you will need to know how and where to include/reference the file in your scripts – Peter Smith Jul 04 '18 at 11:54
  • @PeterSmith there is no folder where jQuery is saved in, what should I include? – clem995 Jul 04 '18 at 11:55
  • If you are using .NET Core then look [here](https://stackoverflow.com/questions/37923853/how-to-use-jquery-in-asp-net-core) otherwise just Google – Peter Smith Jul 04 '18 at 11:59

1 Answers1

5

How to use jQuery after downloading it using NuGet

You should use Bower or the npm (Node Package Manager) to add the JavaScript libraries instead of using NuGet. Because the usage of NuGet for css/javascript libraries is discouraged.

However, since ASP.NET Core 2.0 and the End of Bower, so we recommend you to use npm (Node Package Manager) to manage css/javascript libraries.

To use the package bootstrap to the .net core project, you need to select your project and add a new file to the project root. While in the template manager (Add->New Item...), search for "npm Configuration file".

Then edit the file and add your dependency, i.e.

package.json (npm):

  "devDependencies": {
    "bootstrap": "4.1.1"
  }

Note: For package.json (npm), once you save, the file will be downloaded in a directory named "node_modules`. This alone won't be enough, as the required files need to be copied over to wwwroot folder, where they can be accessed when the application runs.

For the detailed info, see NPM, BOWER, NUGET, GULP – The Four Horsemen of ASP.NET CORE Apps.

Andy Joiner
  • 5,932
  • 3
  • 45
  • 72
Leo Liu
  • 71,098
  • 10
  • 114
  • 135