0

I am following this older answer I found to a problem I had: Set default for DisplayFormatAttribute.ConvertEmptyStringToNull to false across site

But I am pretty new to MVC, so when he says Then register it in your app_start:

Well App_Start is a folder with some classes in it, I have BundleConfig, FilterConfig, RouteConfing and Startup.Auth So in which of these classes should I register it?

Community
  • 1
  • 1
Bohn
  • 26,091
  • 61
  • 167
  • 254

2 Answers2

1

Global.asax file in the root of your project contains Application_Start method

Mike Debela
  • 1,930
  • 3
  • 18
  • 32
1

First, open your Global.asax file. In there you will find an Application_Start method. It may look something like this (you actual code will vary)

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

The Application_Start method is calling into each of the classes you see in the App_start folder. Originally, we would include all of this code in the Global.asax, but it got pretty full, so a pattern developed to create single purpose classes in App_start and call them.

The line that you need to add could be directly beneath all the other calls like this

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        ModelMetadataProviders.Current = new CustomModelMetadataProvider(); 
    }

If you find that the Application_start method is getting cluttered, you may replicate the pattern by creating a static class in the app_start folder and calling calling a static method to do the actual work.

Rob
  • 1,320
  • 1
  • 8
  • 14