Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The name 'Scripts' does not exists in the current context in MVC

In my mvc application, In the _Layout.cshtml has code below...

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

</head>

But the problem is it says The name 'Scripts' does not exists in the current context.

I have already added the assembly to the reference and to the Bundle config as using System.Web.Optimization;

This happens for @styles also.. What should I do?

like image 254
tarzanbappa Avatar asked May 08 '14 06:05

tarzanbappa


3 Answers

Make sure your ~/Views/Web.Config adds the System.Web.Optimization namespace:

<system.web.webPages.razor>
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization"/>
      </namespaces>
    </pages>
</system.web.webPages.razor>
like image 61
haim770 Avatar answered Oct 14 '22 00:10

haim770


The following in .chtml solves the problem

@using System.Web.Optimization
@Scripts.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
like image 39
zapoo Avatar answered Oct 14 '22 00:10

zapoo


Please Follow My Step will Clear this

First

  • Install Microsoft.AspNet.Web.Optimisation
  • Check that the App_Start Folder contains a BundleConfig.cs File.
  • Add <namespaces> <add namespace="System.Web.Optimization"/> </namespaces> in Views/web.config File
  • Add BundleConfig.RegisterBundles(BundleTable.Bundles); in Global.asax.cs
  • Rebuild and Run it
like image 18
Abdulla Sirajudeen Avatar answered Oct 13 '22 23:10

Abdulla Sirajudeen