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

前端 未结 5 2149
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 22:33

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


    
    

        
相关标签:
5条回答
  • 2020-12-07 22:49

    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
    0 讨论(0)
  • 2020-12-07 23:02

    In VisualStudio 2019,I was able to solve this error. Microsoft.Web.Optimization is now included in the 'Microsoft.AspNet.Web.Optimization' package. Using NuGet Packing Manager download the package. In .cshtml file add "@using System.Web.Optimization;

    0 讨论(0)
  • 2020-12-07 23:04

    The following in .chtml solves the problem

    @using System.Web.Optimization
    @Scripts.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    
    0 讨论(0)
  • 2020-12-07 23:05

    There is still intellisense problem, you can add this code to Application_Start() method that inside global.asax file.

    BundleConfig.RegisterBundles(BundleTable.Bundles);
    
    0 讨论(0)
  • 2020-12-07 23:07

    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>
    
    0 讨论(0)
提交回复
热议问题