MVC 4 set for jquery using {version} not displaying

It drives me crazy. I have a package

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

and in the Scripts folder

  • Jquery-1.9.1.js
  • Jquery-1.9.1.min.js
  • jquery-1.9.1.min.map

and on the layout page:

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

when I run debug or release, it does not load jquery. I entered the code from the debugger, and when the package is created for jquery, it does not contain anything. Does anyone know why the wild card {version} does not collect jquery? Any help was greatly appreciated.

+4
source share
3 answers

For me, the problem was moving the @ Scripts.Render operator ("~ / bundles / jquery") from the bottom of _Layout.cshtml to the beginning. By default, Microsoft places this render statement below the footer. I moved it to the section along with @ Scripts.Render ("~ / bundles / modernizr") and then the script in my index.cshtml started working.

Apparently, the problem was that when my script inside index.cshtml tried to execute, JQuery was not loading yet because it was at the bottom of the page.

+5
source

Do you upload your package to Global.asax?

For instance:

 public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { .... // Register Bundles BundleConfig.RegisterBundles(BundleTable.Bundles); } } 
0
source

I had the same problem and found a fix. I noticed that if I used the jquery file version number instead of the {version} token, which worked fine to use it in bundling / minification. The problem was that it did not replace the {version} token, and then could not pull the jquery file into the package.

It seems that the System.Web.Optimization dll is responsible for converting the {version} token into the package configuration. I ended up using NuGet to update this dll. I also just updated everything related to MVC dll when I was on it (Razor, MVC, web pages, etc.). After that he worked.

You can find out if this is your problem by separating the steps of creating and adding packages to the package configuration. The new package object. put a breakpoint on it. Run the Include method, then execute the add method in the bundle configuration to add a new package. When you enter a package, you can look inside it after it executes the Include method to see if the Item property increases accordingly. It did not increase for me when it was a problem.

Also, the link for switching to MVC 5 from MVC 4 is very well made here. I had some work to update all my assembly links after updating the NuGet packages.

http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and- web-api-2

ASP.NET: This method cannot be called during the initialization phase before launching the application.

0
source

Source: https://habr.com/ru/post/1485071/


All Articles