3

I am new to ASP.NET, though not to web programming (I used PHP until now). Working on my first ASP.NET project (actually, maintaining an existing one) I wanted to use jQuery. I had heard that it is so easy to use in VS2010 - just install it with Nuget and use it. So I installed it with Nuget and now I can't figure out how to use it!

How to I actually get it to be available in my HTML? It seems to just be sitting there in a Scripts folder doing nothing!

4 Answers 4

2

I think if you are using Visual Studio 2010, the default application templates already contain jQuery, so there isn't any need to use NuGet.

Just add a reference of the jQuery script to the page you need, and you are good to go:

<head runat="server">
    <script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
</head>

Enter image description here

For IntelliSense: Also add jquery-1.4.1-vsdoc.js.

Enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

Which one? (vsdoc, min, regular)
True, they get you started, but if you utilize nuget with the jQuery libraries, it will notify you and streamline the upgrade process whenever new version of jQuery are available
BTW, jquery-1.4.1-vsdoc.js is for intellisence support in VS...So, you can add that also.
@KPL Still not getting Intellisense :(
Worth mentioning: If you are using ASP.NET's script bundling capabilities (available in MVC 4 project types, and I think available for traditional ASP.NET web forms) you get an additional benefit where NuGet will auto update your package.config file with the latest library version number. More on script bundling here: asp.net/mvc/tutorials/mvc-4/bundling-and-minification
2

Just add a reference to the script you want to use on the page you need it on, for example, in the head-tag:

<head>
    <script type="text/javascript" src="/Scripts/jquery.min.js"></script>
</head>

Of course, the src should be relative to your page and the script.


If you are using ASP.NET MVC and the Razor-engine, you can use:

<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.min.js")"></script>

Ideally, you would add this to the _layout file in the Views > Shared folder. That way it turns up on all pages (views).

Comments

1

NuGet simply downloads the jQuery library. You need top drag the script file(s) to your pages and VS will automatically create a script reference of the form:

<script src="~/Scripts/jquery... />

And you can start using it then.

3 Comments

And I will get the famous Intelisense?
Yes, you should because you are using VS2010
I am not getting Intelisense
-2

If your question is how to get JQuery in your html, Simply add a script tag in the head of your HTML, since your using VS2010, you should be able to drag-and-drop the script file into the HTML file, it will create the script tag

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.