views:

207

answers:

3

Hi guys, I know this is wierd, but I am using ASP.NET MVC, I have real simple jQuery on 2 views. One view is the Home page and the other is an item details page. This page is opened using an Action Link on Home Page. The jquery on item details page does not fire at all.

$(function() {
        alert('Fired!');
        $('#contact').hover(function() {
            $('#conDetails').addClass("gifBack");
        });

    });

This jQuery when put on Home page, shows the alert box but not on the details page. Am I doing something stupid here.

A: 

You must put a clientID and not the ID of control.

pho3nix
Well but why would the alert not show on the details view page?
theraneman
+2  A: 

I couldn't think of a reason why the alert is not being fired in the details page unless there is no jquery javascript referenced in that page?

codemeit
I knew that should have been the problem. I was addding jQuery.1.3.2.js like this ../../Scripts/jQuery.1.3.2.js. Actually, it should be just /Scripts/jQuery.1.3.2.js. Earlier path would not work on child pages.
theraneman
In that case, I am right :D
codemeit
<script type="text/javascript" src="<%=Page.ResolveClientUrl("~/Scripts/...js")%>"></script>
Tracker1
A: 

Just made a blog post with a few HtmlHelper extension methods for dealing with adding libraries. Frugal Code blog - Handling Scripts in ASP.Net MVC

Tracker1