Monday, July 22, 2019

The Name BundleConfig Does Not Exist in the Current Context

สรุป
 - เพิ่ม  BundleConfig.RegisterBundles(BundleTable.Bundles); ใน    file Global.asax
 - เพิ่ม using System.Web.Optimization; 


Given that there are currently no results on The Web that give a good answer to the following error, I thought I’d help out and supply the information.
The error is…
“The name ‘BundleConfig’ does not exist in the current context”
Usually this means you have the following line of code in your Global.asax.cs file, perhaps in an ASP.NET MVC project.
BundleConfig.RegisterBundles(BundleTable.Bundles);
There are two possible reasons for this error.

Namespace

The most obvious and easy to fix error will be that when you added your App_Start/BundleConfig class, Visual Studio put in the namespace YourApp/App_Start namespace. All of the other App_Start classes will be in the YourApp namespace. So go edit:
namespace YourApp.App_Start
{
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            //...
And change it to:
namespace YourApp
{
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            //...

Optimization Package

The second most obvious reason will be that you don’t have the System.Web.Optimization assembly.
To fix this, right-click on your solution, click on “Manage NuGet packages for solution” and search for…
Microsoft ASP.NET Web Optimization Framework
Then just install the package and you’re good to go.

No comments:

Post a Comment