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.