简体   繁体   English

Javascript路径问题asp.net MVC

[英]Javascript path issue asp.net mvc

I'm creating an application in asp.net mvc. 我在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. 在将javascript添加到我的剃刀文件中时获得正确的路径。 but i have javascript reference inside another javascipt file like below 但是我在另一个如下的javascipt文件中有javascript参考

$.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. 现在当我访问默认URL时,我的jquery工作正常。但是当我使用任何Controller.MEthod url时,我得到jquery错误。

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. 我很确定它的一些路径问题。当我使用任何控制器/方法url时,我的应用程序没有获得包含在另一个JS文件路径内的JS。

kindly help.. 请帮助。

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 尝试在“网络”选项卡中查看Firebug,以查看您的应用程序试图在何处查找丢失的脚本的确切位置

EDIT: I wouldn't be surprised if while in a /home/whatever (controller/action) your application will look for jquery.cookie.js in 编辑:如果在/ home /无论(控制器/动作)中的应用程序在以下位置查找jquery.cookie.js ,我都不会感到惊讶

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

EDIT #2 Try and specify an absolute path in your js file. 编辑#2尝试在js文件中指定绝对路径。 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 比方说,jquery.cookie.js位于CND /脚本/你应该这样做

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM