0

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..

1 Answer 1

1

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')
Sign up to request clarification or add additional context in comments.

4 Comments

I checked,When i'm in root url it takes path correctly from localhost/scripts/jquery.cookie.js.but when i access localhost/controller/method it is searching js file in localhost/controller/scripts/jquery.cookie.js.How can i fix it?any ideas?
Edited my answer. Let me know if you need anymore help
hey,$.include('../scripts/jquery.cookie.js') solved my problem.no jquery error now.thanks.
Glad I could help :). Remember to user firebug "net" (or chrome "network") tab in these type of situations. It really helps

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.