The Name 'Scripts' Does Not Exist in the Current Context

There is a very small bug in the MVC 4 Empty Template that can be seen when you create a new MVC 4 Application with an "Empty" template and start adding views for CRUD operations (using scaffolding). And when you run the application and try to navigate (to http://localhost:port/controller/Create or http://localhost:port/controller/Edit) in "Edit.cshtml" and "Create.cshtml" views, you get the following error:

Now, if you open the "Edit.cshtml" and "Create.cshtml" views, you will notice something missing there.

So, why is this issue occuring?

As a developer we expect to run a template (empty, internet, intranet etc) at the very beginning, I guess you are thinking the same. From my point of view, the MVC product team forgot to pack a pre-release version of the "Optimization" pack with the "Empty" template; other templates work fine.

How do you fix this?

Look, there are some even worse alternatives:

First One: You can delete the above codes (in red rectangular box) and then running your application will work. But the jQuery validations of any new entry or editing will no longer be available for you on the view.

Second One: You can use other templates (Internet, Intranet etc) that have everything already and will work for you.

And I'm not going to use any of them, what I'm going to do is install the "Optimization" pack and then add namespaces in the config file.

Step 1: Install from NuGet

Open the power console and install this package using the following command:

PM> Install-Package Microsoft.Web.Optimization -Pre

Step 2: Add a namespace reference in the config files

Open both Web.config files (the first one is in the root and the second one is in the view folder) and add this new namespace.

<add namespace="System.Web.Optimization" />

Now you are all set to run, the bug will no longer occur.

I hope this helps. Thanks.