Neelam
Neelam

Reputation: 1068

Javascript path issue asp.net mvc

I'm creating an application in asp.net mvc. I know i can use

 @Url.Content("~/Scripts/jquery-1.5.1.min.js")

to get my path right while adding javascript to my razor file. but i have javascript reference inside another javascipt file like below

$.include('Scripts/jquery.cycle.all.min.js')
$.include('Scripts/jquery.cookie.js')

now when i access my default url, my jquery works fine.but when i use any Controller.MEthod url I get jquery errors.

I'm pretty sure its some path issue.My application is not getting the JS which is included inside another JS file's path right when i use any controller/method url.

kindly help..

Upvotes: 0

Views: 934

Answers (1)

Mihai
Mihai

Reputation: 2760

It might be because

$.include('Scripts/jquery.cookie.js') 

is a relative path (relative to the controller you're currently in) while

@Url.Content("~/Scripts/jquery-1.5.1.min.js") 

is an absolute path.

Try and look in Firebug in the "Net" tab to see where exactly where your application trying to find the scripts you're missing

EDIT: I wouldn't be surprised if while in a /home/whatever (controller/action) your application will look for jquery.cookie.js in

/home/whatever/scripts/jquery.cookie.js

EDIT #2 Try and specify an absolute path in your js file. Something like this

$.include('../scripts/jquery.cookie.js')

User "../" to navigate to the root of your application. Let's say that jquery.cookie.js is located in cnd/scripts/ you should do something like

$.include('../../scripts/jquery.cookie.js')

Upvotes: 1

Related Questions