0

I'm trying to use a dummy TempDataProvider for some of my controllers.

The provider looks like this.

 public class NullTempDataProvider : ITempDataProvider {

    public IDictionary<string, object> LoadTempData(ControllerContext controllerContext) {
        return new TempDataDictionary();
    }

    public void SaveTempData(ControllerContext controllerContext, IDictionary<string, object> values) {

    }
}

But I'm getting an error that says

System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.Mvc.Controller.PossiblyLoadTempData()

Any help for figuring out the reason for it is much appreciated.

Johan Alkstål
  • 5,225
  • 9
  • 36
  • 48

1 Answers1

0

By overriding CreateTempDataProvider() and returning an instance of NullTempDataProvider, this problem goes away.

Johan Alkstål
  • 5,225
  • 9
  • 36
  • 48