0

I have following code in the App_Start/BundleConfig.cs

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

    bundles.Add(new ScriptBundle("~/bundles/datatable").Include(
                    "~/Content/DataTables-1.10.7/media/js/jquery.dataTables.min.js"));

    bundles.Add(new StyleBundle("~/Content/css").Include(
                    "~/Content/site.css", 
                    "~/Content/DataTables-1.10.7/media/css/jquery.dataTables.min.css"));

and in the Views/Shared/_Layout.cshtml

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/datatable")

and CSS and Datatable just does not work, but when I add manualy

<link href='@Url.Content("~/Content/DataTables-1.10.7/media/css/jquery.dataTables.min.css")' rel="stylesheet" />

<script src='@Url.Content("~/Content/DataTables-1.10.7/media/js/jquery.dataTables.min.js")' type="text/javascript"></script>

it starts to work. What am I doing wrong ?

Muflix
  • 6,192
  • 17
  • 77
  • 153
  • Rename js scripts with "min" to ones without it. Bundles have problems when including scripts with "min" in their names. Look at this question: http://stackoverflow.com/questions/11980458/bundler-not-including-min-files – Jacob Sobus Apr 01 '16 at 12:47

1 Answers1

0

Inspect the source code of the web page from the browser and be sure that;

jquery.dataTables.min.js is loading after jquery.min.js

Change the order in your _Layout.cshtml as:

@Scripts.Render("~/bundles/jquery")    
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/datatable")

EDIT :

It may also be about web.config settings.

If you have "Debug = True" in your web.config, minimized javascript files are not include in bundles.

Add this to your BundleConfig.cs :

#if DEBUG
        //by default all minimized files are ignored in DEBUG mode. This will stop that.
        bundles.IgnoreList.Clear();
#endif