Asp.Net和jquery-ui:引用页面上请求的现有文件

时间:2021-11-20 16:55:59

I am currently facing the problem that on one of my pages, the page requests a file named "jquery-ui-1.11.1.min.js" which causes a 404 file not found error. This is because the correct file name is "jquery-ui.min-1.11.1.js". So, for some reason, something uses wrong jquery references.

我目前面临的问题是,在我的一个页面上,页面请求名为“jquery-ui-1.11.1.min.js”的文件,该文件导致找不到404文件错误。这是因为正确的文件名是“jquery-ui.min-1.11.1.js”。所以,由于某种原因,某些东西使用了错误的jquery引用。

My MasterPage has the following references (among others):

我的MasterPage有以下参考资料(其中包括):

<asp:ScriptManager runat="server" EnablePageMethods="true" LoadScriptsBeforeUI="true">
  <Scripts>
     <asp:ScriptReference Name="MsAjaxBundle" />
     <asp:ScriptReference Name="jquery" />
     <asp:ScriptReference Name="jquery.ui.combined" />
  </Scripts>
</asp:ScriptManager>

What I have tried:

我试过的:

  • Clean/rebuild the solution
  • 清理/重建解决方案
  • Remove/Re-install jquery-ui with NuGet
  • 使用NuGet删除/重新安装jquery-ui
  • Search for the wrong reference in the project (nothing found)
  • 在项目中搜索错误的引用(找不到任何内容)

Another way of solving this would be to simply add a copy of the JS file and rename it so that it matches the requested file's name. But then again, this is a very dirty solution because it doesn't solve the root cause of problem.

解决这个问题的另一种方法是简单地添加JS文件的副本并重命名它,使其与所请求文件的名称相匹配。但话说回来,这是一个非常肮脏的解决方案,因为它无法解决问题的根本原因。

The missing file causes problems like not-working datepicker, etc. I have temporarily solved it by putting this on top of the page:

丢失的文件会导致诸如not-working datepicker等问题。我暂时通过将其放在页面顶部来解决它:

<script type="text/javascript" src='<%= ResolveClientUrl("~/Scripts/jquery-ui.min-1.11.1.js") %>'></script>

However, this is terrrible to maintain, so I would like to have the following things:

但是,这很难维护,所以我希望有以下几点:

  • A working way to reference ALL jQuery stuff in the ScriptManager on the MasterPage (jQuery-2.1.1, jQuery-ui and jquery-ui.css). With the current references, only jQuery-2.1.1 seems to work.
  • 在MasterPage(jQuery-2.1.1,jQuery-ui和jquery-ui.css)上的ScriptManager中引用所有jQuery内容的工作方式。使用当前引用,只有jQuery-2.1.1似乎可以工作。
  • Find and eliminate the one that requests the wrong "jquery-ui-1.11.1.min.js" file
  • 找到并消除请求错误的“jquery-ui-1.11.1.min.js”文件

To me, bundling is still a blackbox and I couldn't find any usable solution to include everything that jQuery needs onthe MasterPage. Any suggestions?

对我来说,捆绑仍然是一个黑盒子,我找不到任何可用的解决方案来包含jQuery在MasterPage上需要的一切。有什么建议么?

1 个解决方案

#1


0  

I have found the cause of the problem. The following line in BundeConfig.cs was the reason for the wrong request:

我找到了问题的原因。 BundeConfig.cs中的以下行是错误请求的原因:

bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));

This apparently also included the "min" version of jquery-ui.

这显然也包括了jquery-ui的“min”版本。

My solution for bundling jquery now is:

我现在捆绑jquery的解决方案是:

bundles.Add(new ScriptBundle("~/bundles/jquery")
                .Include("~/Scripts/jquery-{version}.js",
                         "~/Scripts/jquery-ui-{version}.js"));

This solves the maintainability issue and causes all pages that use the Site.Master to correctly use jQuery.

这解决了可维护性问题,并导致使用Site.Master的所有页面正确使用jQuery。

#1


0  

I have found the cause of the problem. The following line in BundeConfig.cs was the reason for the wrong request:

我找到了问题的原因。 BundeConfig.cs中的以下行是错误请求的原因:

bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));

This apparently also included the "min" version of jquery-ui.

这显然也包括了jquery-ui的“min”版本。

My solution for bundling jquery now is:

我现在捆绑jquery的解决方案是:

bundles.Add(new ScriptBundle("~/bundles/jquery")
                .Include("~/Scripts/jquery-{version}.js",
                         "~/Scripts/jquery-ui-{version}.js"));

This solves the maintainability issue and causes all pages that use the Site.Master to correctly use jQuery.

这解决了可维护性问题,并导致使用Site.Master的所有页面正确使用jQuery。