试图让Telerik ScriptRegistrar加载Telerik脚本和自定义脚本(Trying to get Telerik ScriptRegistrar to load Telerik sc

编程入门 行业动态 更新时间:2024-10-28 10:29:12
试图让Telerik ScriptRegistrar加载Telerik脚本和自定义脚本(Trying to get Telerik ScriptRegistrar to load Telerik scripts and custom script)

我在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)需要指定在哪里? 只有在DefaultGroup之后? 还是在任

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?

最满意答案

我认为最简单的方法是:

@(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group .DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/").Combined(true) .Compress(true)).jQuery(false))

很抱歉,如果最终看起来有点压缩 - 代码片段样式拒绝应用任何其他设置。 无论如何,一旦你完成了注册,你在页面的head部分注册了以下内容:

<script src="@Url.Content("~/Assets/JavaScripts/jQuery/jquery-1.6.2.min.js")" type="text/javascript"></script>

这将正确链接到您自己的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:

@(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group .DefaultPath("~/Assets/telerikaspnetmvc/2011.2.712/Scripts/").Combined(true) .Compress(true)).jQuery(false))

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:

<script src="@Url.Content("~/Assets/JavaScripts/jQuery/jquery-1.6.2.min.js")" type="text/javascript"></script>

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.

更多推荐

本文发布于:2023-08-06 06:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1445056.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   自定义   加载   ScriptRegistrar   Telerik

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!