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.
Troubleshooting MVC ErrorĀ Ā ‘Scripts’ does not exist in the current context:
- Check whether the namespaceĀ System.Web.OptimizationĀ is in the reference list.
- 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.
- 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.