Asp.net mvc4 change jquery version

I ran into some problems with cross browser with jquery, after some research, I found that my application works with jquery 1.8.11 or at least it seems so.

My project is an MVC4 asp.net C # application.

Actually I'm trying to disable - enable some buttons, it works fine on IE, but not in chrome / firefox / safari.

<ul class="ui-grid-d"> <li class="ui-block-a"><a id="MostrarDetallePedido" class="ui-btn ui-btn-up-a" disabled="disabled" href="/Documentos/Docs/DocsDetalle?StrIdDocumento=01500___00000000000000041" data-role="button" data-theme="a" data-ajax="false"><span aria-hidden="true" class="ui-btn-inner"><span class="ui-btn-text">Detalle</span></span></a></li> <li class="ui-block-b"><a id="ItemCondiciones" class="ui-state-disabled ui-btn ui-btn-up-b" disabled="disabled" href="/Documentos/Docs/DocsDetalle?StrIdDocumento=01500___00000000000000041" data-role="button" data-theme="b" data-ajax="false"><span aria-hidden="true" class="ui-btn-inner"><span class="ui-btn-text">Condiciones</span></span></a></li> <li class="ui-block-c"><a id="ItemEliminar" class="ui-state-disabled ui-btn ui-btn-up-c" disabled="disabled" href="/Documentos/Docs/DocsDetalle?StrIdDocumento=01500___00000000000000041" data-role="button" data-theme="c" data-ajax="false"><span aria-hidden="true" class="ui-btn-inner"><span class="ui-btn-text">Eliminar</span></span></a></li> <li class="ui-block-d"><a id="ItemAdiciones" class="ui-state-disabled ui-btn ui-btn-up-d" disabled="disabled" href="/Documentos/Docs/DocsDetalle?StrIdDocumento=01500___00000000000000041" data-role="button" data-theme="d" data-ajax="false"><span aria-hidden="true" class="ui-btn-inner"><span class="ui-btn-text">Adiciones</span></span></a></li> <li class="ui-block-e"><a id="ItemComponentes" class="ui-state-disabled ui-btn ui-btn-up-e" disabled="disabled" href="/Documentos/Docs/DocsDetalle?StrIdDocumento=01500___00000000000000041" data-role="button" data-theme="e" data-ajax="false"><span aria-hidden="true" class="ui-btn-inner"><span class="ui-btn-text">Componentes</span></span></a></li> </ul>​ 

I tried

 $('#ItemEliminar').addClass('ui-disabled');​ 

This way

 $('#ItemEliminar').button({ disabled: false }).button('enable').button('refresh'); 

I did some tests using my own scripts at http://jsfiddle.net/9386M/1/ and it works fine with jquery 1.8.2.

Well, all I need to know is how to change my jquery library, I looked at _Layout.cshtml, but I can not find links to my jquery lib.

In the script folder, I found jQuery-u-1.8.11.js jQuery-u-1.8.11.min.js jQuery-1.6.4.js jQuery-1.6.4.min.js

+7
source share
2 answers

Two ways to do this:

  • Right-click on your solution, select "Manage NuGet Packages ...", go to "Updates" in the dialog that opens, and update jQuery.

  • Go to /App_Start/BundleConfig.cs and update the jQuery link. You also need to put the appropriate jQuery library version in the /Scripts/ folder.

And you can always find all the solutions for the "jQuery" line (press Ctrl + Shift + F and select "Whole Solution" in the "Look in" drop-down list)

+11
source

MVC4 uses binding.

Go to App_Start => Open BunlingConfig.cs

You will see the following:

  // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include( "~/Scripts/jquery-ui-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( "~/Scripts/jquery.unobtrusive*", "~/Scripts/jquery.validate*")); // and bunch of other bundles } 

The first line here creates a package for jQuery.

You can change it below:

  bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-1.8.2.min.js")); 

make sure you download the library if you want to use cdn as shown below:

  bundles.UseCdn = true; const string jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"; bundles.Add(new ScriptBundle("~/bundles/jquery", jqueryCdnPath).Include("~/Scripts/jquery-{version}.js")); 

You can also create packages for your files. You can learn more about this here http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4

In the layout file, they are consumed, as shown below:

  @Scripts.Render("~/bundles/jquery") 

Hope this helps.

+3
source

All Articles