Search code examples
javascriptc#jqueryasp.net-mvcbundling-and-minification

Cannot bundle jQuery files in MVC


I have 2 js files:

  1. jquery.validate.js
  2. jquery-1.10.2.min.js
    along with other files I'm using mvc bundling technique to bundle them.

I have a form with a lot of required invisible fields(these fields are needed in other pages).
When I do form.Valid(), it is validating even the invisible fields and says form is invalid even when I fill in all the data.

When I don't bundle it all works fine.
So I think the problem is with bundling those 2 files.
My question would be why is that is there something with these files we CANNOT bundle?

Any help would be appreciated.


Solution

  • I'm able to bundle these files (and others), but in one project, I have them grouped separately. In other words, I have JQuery-*.js bundled by itself, and have the Validate and other helper files in another bundle. The main reason I did it this way is because not all of my screens need the Validate portion, so it's only loaded when necessary. In another project, I bundle them together. Works in both cases.

    To use the bundled files, in your Razor code, you need something like:

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

    I would include JQuery bundle before the Validate bundle, if you use separate bundles. If using one bundle, put the validate last in the bundle list.