MVC 4 Error: CS0103: The name ‘Scripts’ does not exist in the current context

Today, I was creating a MVC 4 web application. On building the project, I got an error “CS0103: The name ‘Scripts’ does not exist in the current context“. After analyzing, I figured out the problem is because of the namespace System.Web.Optimization was not added to the Web.config file in the view folder. After adding the namespace, the error vanished.

System.Web.Optimization is used for bundling and minifying js and css files. By bundling and minimizing the file size, this class improves the performance of the ASP.NET Web Forms and MVC applications. This namespace is provided by Microsoft. You can download the namespace from NuGet. In NuGet search for Optimization. In the search result you can see the package Microsoft ASP.NET Web Optimization Framework.

If you find similar error, follow the below steps to trouble shoot and fix the error.

MVC-4-Error-CS0103-01

Troubleshooting MVC Error  ‘Scripts’ does not exist in the current context:

  1. Check whether the namespace System.Web.Optimization is in the reference list.
    MVC-4-Error-CS0103-03
  2. If it’s not found in the reference list, then install it from NuGet. Right click the project and select Manage NuGet Packages…. In the Manage NuGet screen, search for Optimization. From the result screen install the package Microsoft ASP.NET Web Optimization Framework.
    MVC-4-Error-CS0103-02
  3. Then open the Web.config file in the View folder. look for the name space System.Web.Optimization in the <namespaces> section. Add the section if it is not there.
    MVC-4-Error-CS0103-04


2 thoughts on “MVC 4 Error: CS0103: The name ‘Scripts’ does not exist in the current context”

  1. I now it’s going to sound stupid, but check if you have your

    namespace MainApp
    {
    public class BundleConfig

    BundleConfig class, you won’t be able to see anything in your HTML if you do not have this class, also, in your global.asax check that you have.
    BundleConfig.RegisterBundles(BundleTable.Bundles); on your app_start method.

    Have fun!

    Reply
  2. Did that…didnt work. I still get the error, I have the ref, and I have the namespace added in the config file in the Views folder….now what.

    Reply

Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.