Creating Bundles with MVC Framework

In an MVC Framework web application I can create multiple bundles from the App_Start/BundleConfig.cs file. Within that file I can define each bundle together with its content. I can as well to specify that all the files of a particular type included in a target folder should be added to the bundle.

Here is an example on how to define a bundle which contains two well specified JS files plus all the JS files from a particular folder:

bundles.Add(new ScriptBundle("~/bundles/angularApp").Include(
            "~/app/angularApp.js",
            "~/app/controllers/*.js",
            "~/app/statesConfig.js"));

To render a bundle within a Razor view I can use the @Script.Render (because in this case we have a script bundle) instruction:

@section scripts
{
    <script src="~/Scripts/angular.min.js"></script>
    <script src="~/Scripts/angular-ui-router.min.js"></script>
    @Scripts.Render("~/bundles/angularApp")
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s