尝试让 Telerik ScriptRegistrar 加载 Telerik 脚本和自定义脚本
我在 ASP.NET MVC 3 razor 应用程序中使用最新版本的 Telerik MVC 扩展。我还下载了最新版本的 jQuery。
我的 jQuery 文件位于与 Visual Studio 的默认目录不同的目录中。原因是因为我下载了最新版本的jQuery jquery-1.6.2.min.js。我的 Telerik MVC 内容和脚本目录位于不同的目录中。据我所知,Telerik 脚本需要首先加载 jQuery 文件。我已经删除了 ASP.NET MVC 应用程序默认附带的内容和脚本目录。
Telerik 脚本目录:
~/Assets/telerikaspnetmvc/2011.2.712/Scripts/
我的 jQuery 目录:
~/Assets/JavaScripts/jQuery/
我将 ScriptRegistrar 更改为以下内容:
@(Html.Telerik().ScriptRegistrar()
.DefaultGroup(group => group
.DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/")
.Compress(true)
)
.Scripts(scripts => scripts
.AddGroup("JavaScriptAssetLocation", group => group
.DefaultPath("~/Assets/JavaScripts/jQuery/")
.Add("jquery-1.6.2.min.js")
.Compress(true)
)
)
.jQuery(false)
)
这给了我一个错误。我交换了 2,以便它可以首先读取 jQuery,如下所示,但它似乎仍然首先加载默认的 Telerik JavaScript 文件并导致错误。这是更改后的代码:
@(Html.Telerik().ScriptRegistrar()
.Scripts(scripts => scripts
.AddGroup("JavaScriptAssetLocation", group => group
.DefaultPath("~/Assets/JavaScripts/jQuery/")
.Add("jquery-1.6.2.min.js")
.Compress(true)
)
)
.DefaultGroup(group => group
.DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/")
.Compress(true)
)
.jQuery(false)
)
我在这里做错了什么?请提供代码示例以说明必须如何完成。
只是另一个问题。我是否需要为每个组指定 compress(true) 还是一次就足够了? jQuery(false) 需要在哪里指定?仅在默认组之后?或者任何地方?
I am using the latest version of Telerik MVC extensions with my ASP.NET MVC 3 razor application. I have also downloaded the latest version of jQuery.
I have my jQuery file in a different directory as to what comes default with Visual Studio. The reason for this is because I have downloaded the latest version of jQuery jquery-1.6.2.min.js. I have my Telerik MVC content and scripts directories in a different directory. As to what I have seen the Telerik scripts needs the jQuery file to be loaded first. I have deleted the content and scripts directories that come by default with an ASP.NET MVC application.
Telerik scripts directory:
~/Assets/telerikaspnetmvc/2011.2.712/Scripts/
My jQuery directory:
~/Assets/JavaScripts/jQuery/
I changed the ScriptRegistrar to that of below:
@(Html.Telerik().ScriptRegistrar()
.DefaultGroup(group => group
.DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/")
.Compress(true)
)
.Scripts(scripts => scripts
.AddGroup("JavaScriptAssetLocation", group => group
.DefaultPath("~/Assets/JavaScripts/jQuery/")
.Add("jquery-1.6.2.min.js")
.Compress(true)
)
)
.jQuery(false)
)
This gave me an error. I swapped the 2 around so that it can read jQuery first as below but it still seems to load the default Telerik JavaScript files first and results in errors. This is the changed code:
@(Html.Telerik().ScriptRegistrar()
.Scripts(scripts => scripts
.AddGroup("JavaScriptAssetLocation", group => group
.DefaultPath("~/Assets/JavaScripts/jQuery/")
.Add("jquery-1.6.2.min.js")
.Compress(true)
)
)
.DefaultGroup(group => group
.DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/")
.Compress(true)
)
.jQuery(false)
)
What am I doing wrong here? Please provide code samples as to how it must be done.
Just another question. Do I need to specify Compress(true) per group or is once enough? And jQuery(false) needs to be specified where? Only after DefaultGroup? Or anywhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这里最简单的事情如下:
抱歉,如果这最终看起来有点压缩 - 代码片段样式拒绝与任何其他设置一起应用。无论如何,一旦您完成此操作,请在页面的头部注册以下内容:
这将正确链接到您自己的 jQuery 版本,同时确保默认组的 DefaultPath 已更改。
至于在这里使用压缩,我认为它不会有多大作用。这实际上只适用于当您在添加了多个脚本的组中使用 .Combined(true) 时(例如 Telerik 组件的默认组)。如果您只使用单个文件(jquery-1.6.2.min.js),则确实没有必要。因此,每当您想要压缩组合组时,请确保使用 .Combined(true) (我必须在上面添加它)。这需要为每个组添加。
I think the easiest thing to do here would be the following:
Sorry if this ends up looking a bit compressed - the code snippet style refused to be applied with any other setting. Anyways, once you have done that register the following in the head section of your page:
This will link properly to your own jQuery version while ensuring that the default group's DefaultPath is changed.
As far as using compression here I don't think it would do much. This is really only good for when you use .Combined(true) in a group that has several scripts that are being added (the default group for the Telerik components for example). If you're just using a single file (jquery-1.6.2.min.js) there's really no need. So, just make sure you use .Combined(true) (I had to add it above) whenever you want to compress a combined group. This would need to be added for every group.