Javascript error in *.min.js.map files

I’ve been getting an JavaScript error:

JavaScript critical error at line 2, column 14 in http://localhost:53885/Scripts/jquery.unobtrusive-ajax.min.js.map\n\nSCRIPT1004: Expected ‘;’

This has happened in a few different files, I tried regenerating the *.min.js and *.min.js.map files, but it just wouldn’t go away.

Eventually with a bit of searching Ifound the cause of the problem, Asp.Net MVC Bundles.

Our code was:

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

and we changed it to:

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

This stops the bundle loading the map files.

Advertisements

Entity Framework and recreating the database when the model changes.

I’ve just started a new MVC5 project, and just couldn’t remember exactly how to do this.

So:

  1. Create a new project
  2. Create your models
  3. Create your DbContext
  4. Create a Database Initializer
  5. Add Database Initializer into Global.asax
public class ApplicationDbContextInitializer : DropCreateDatabaseIfModelChanges<ApplicationDbContext>
{
    protected override void Seed(ApplicationDbContext context)
    {
        base.Seed(context);
    }
}
Database.SetInitializer<ApplicationDbContext>(new ApplicationDbContextInitializer());