tags:

views:

79

answers:

2

I'm following this tutorial but it doesn't tell me how to run this jQuery script. Since this script will be run pretty much everywhere, I should attach this script to the Masterpage right, but how?

I guess what I'm asking is, what HTML tag do I need to reference the jQuery script, and where to put the jQuery code.

I have this library already in my project: alt text

Thanks.

+3  A: 

Take a look here:

Using scripts in a master page with ASP.NET MVC

Leniel Macaferi
+3  A: 

jQuery is a client-side scripting tool. ASP .Net is a server-side language.

You are correct, to add a reference to jQuery for all pages it is a good idea to use a master page for this purpose.

In the master page, you simply add the HTML script reference to the master page:

<@ MasterPage .... >

<html>
<head>
  <script src="../Scripts/jquery-1.4.1.js"></script>
</head>
<body>
 <asp:ContentPlaceHolder id="Content" />
</body>
</html>

Add a script element for each of the jQuery scripts. Make sure the jquery-1.4.1.js is the first referenced though.

Also make sure you use the <script></script> instead of <script/> due to some browser issues.

Some newer Visual Studio MVC project files do this script referencing for you (as Lenial mentioned), and this may be easier.

Russell