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?
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>
The following in .chtml solves the problem
@using System.Web.Optimization
@Scripts.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
Please Follow My Step will Clear this
First
Microsoft.AspNet.Web.Optimisation
App_Start
Folder contains a BundleConfig.cs
File.<namespaces> <add namespace="System.Web.Optimization"/> </namespaces>
in Views/web.config
FileBundleConfig.RegisterBundles(BundleTable.Bundles);
in Global.asax.cs
仍然存在智能感知问题,您可以将此代码添加到 global.asax 文件中的 Application_Start() 方法中。
BundleConfig.RegisterBundles(BundleTable.Bundles);
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;
The easiest way to fix this issue is by downloading (Microsoft.AspNet.Web.Optimization) from Nuget Package Manager.
Steps:
you probably need to add the nuget package
Microsoft.AspNet.Web.Optimization
to your project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.