Search code examples
javascriptasp.net-mvctwitter-bootstrapbundling-and-minificationbootstrap-table

JavaScript error using bootstrap-table


I'm trying to use bootstrap-table with MVC. I have the following files in scripts and content:

bootstrap-table.js
bootstrap-table.min.js
bootstrap-table-locale-all.js
bootstrap-table-locale-all.min.js

bootstrap-table.css
bootstrap-table.min.css

I'm then using the following in the bundleconfig.cs file:

        bundles.Add(new ScriptBundle("~/bundles/bootstraptable").Include(
                  "~/Scripts/bootstrap-table*"));

        bundles.Add(new StyleBundle("~/Content/bootstraptable").Include(
                  "~/Content/bootstrap-table*"));

and these in the "_Layout.cshtml" file:

    @Styles.Render("~/Content/bootstraptable")
    @Scripts.Render("~/bundles/bootstraptable")

I also have jQuery and Bootstrap included (and working), so I don't think it's a dependency issue.

When I run the project (before I even try doing anything with a table), I get:

Unable to get property 'locales' of undefined or null reference

There's no NuGet package for this, so I had to add the files manually, so perhaps I missed something. But according to the website (http://bootstrap-table.wenzhixin.net.cn/getting-started/), it would seem I have what I need.

Anyone had this issue or have any idea what I'm doing wrong?

Thanks.


Solution

  • So apparently the list of the files in the bundle is important for this. When I bundled it with the wildcard, it didn't work. When I switched it to

            bundles.Add(new ScriptBundle("~/bundles/bootstraptable").Include(
                      "~/Scripts/libs/bootstrap-table.js",
                      "~/Scripts/libs/bootstrap-table-en-US.js"));
    

    explicitly putting the 2 necessary files in the bundle (I replaced the "all" locale with just the one I need), then it worked.