Tech Junkie Blog - Real World Tutorials, Happy Coding!: End-to-End ASP.NET MVC : Add JQuery Library Using NuGet

Saturday, June 18, 2016

End-to-End ASP.NET MVC : Add JQuery Library Using NuGet

In the previous blog we've created an empty ASP.NET MVC  project.  It's a great starting point but, it's missing a lot things that we will need later.  In this blog we will add JQuery to the empty ASP.NET MVC  project that we've just created.

Step-By-Step Instructions:

1. Open the empty ASP.NET MVC project that you've just created

2.  Right click on the the "References" node in the "Solution Explorer", then select "Manage NuGet Packages"

3. In the search box on the right of NuGet window type "JQuery", the search result will be displayed, you will see that an old version is installed for the project.  Click on the "Update" button to update to the latest version as of this post which is 3.3.1.

4. Click on the "OK" button on the "Preview Changes" dialog

5. Now the latest version of jQuery is installed

6.  Now you should see the JQuery scripts in the "Scripts" folder

7.  To use the JQuery .js script reference the jquery-3.3.1.min.js file with the following code between the <head> element
<script src="~/Scripts/jquery-3.3.1.min.js"></script>

8. You can use the following code to test if JQuery is working in your ASP.NET MVC project
    $(document).ready(alert("jquery is working"));

9. So you can modify the "Index.cshtml" to have the following markup to test if JQuery is working or not, if JQuery is working you should get an alert box saying "jquery is working"
    Layout = null;

<!DOCTYPE html>

    <meta name="viewport" content="width=device-width" />
    <script src="~/Scripts/jquery-3.3.1.min.js"></script>
        Hello World! 
    $(document).ready(alert("jquery is working"));


Similar Posts:


  1. Its recommended that we use Bower Config to for client side dependencies

  2. Thank you for the tutorial, so far works as expected

  3. before running application ,please match the name of the file in script folder with the name in tagging you have added on cshtml view

  4. This is not what I was looking for, but it helped thanks.

  5. I'm not 100% sure but I think you should create bundles in "BundleConfig.cs" and then initialize them in your "_layout.cshtml".

    //create jquery bundle from files that are located in ~/scripts/ and start with jquery-
    bundles.Add(new ScriptBundle("~/bundles/jquery")

    //and then initialize the bundle at the bottom of your layout

  6. Thanks for the valuable information and insights you have so provided here... ring camera

  7. composed language in the third thousand years BC. C. In any case, the distinctions in working strategies Cooperate Identity design

  8. Your blogs are easily accessible and quite enlightening so keep doing the amazing work guys. Shock Wave Therapy


Search This Blog