ASP.Net MVC 4 Bundles

asp.net-mvc, jquery

Solution

You need to create the bundle. This is often done in the `App_Start\BundleConfig.cs` file in your ASP.NET MVC 4 project. It is all explained in Bundling and Minification .

In the `BundleConfig` class you need something like this (this method should execute in `Application_Start`):

public static void RegisterBundles(BundleCollection bundles) {
  bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
              "~/Scripts/jquery-{version}.js"));

  bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
              "~/Scripts/jquery.unobtrusive*",
              "~/Scripts/jquery.validate*"));

  // ... more registrations ...
}

The javascript source files should exists in the `Scripts` folder. The tutorial linked above explains how minified versions are bundled in the release build etc.

Problem

Lots of code that I have seen reference this: ``` @section Scripts { @Scripts.Render("~/bundles/jqueryval") } ``` Which is great, and it works...if "something" is included. Do I have to add a reference to get these? Use NuGet? Copy a DLL? Where does this come from? When I run my project, I get a 404 for that resource.

Original source