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.
FYI - I have seen many examples of using Bundles in MVC, but most neglect to mention that the assemblies for this are in System.Web.Optimization.dll and you can get this from NuGet by adding the Microsoft ASP.NET Web Optimization Framework package.
Yes, you must register the bundles in your application.
Global.asax.cs :
BundleConfig.cs :
So when you put this code in your view :
It will render 4 javascript files.
More : Bundling and Minification
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 inApplication_Start
):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.In your project
App_Start/BundleConfig.cs
is the declaration for all bundles. Consider this:In this case if you reference "~/bundles/jqueryval" it will include the 2 listed scripts for you, and as a bonus, it will minify them (if you run your project in "Release" mode).
Take a look at this for more details.
Please not that inside the Include method, it is including for the files in your project.