-1

I have some dummy data inside my helper class. I want to on every mvc4 application startup to call this static method which would generate necessary data.

so I was thinking to store that data in variable inside global.asax and use that variable from controllers

public class MvcApplication: ...
{
    protected void Application_Start()
    {
        var dummyData = DummyData.GetData();
    }
}

But I cannot access this variable from my controller

public ActionResult Index()
{
   var data = MvcApplication// I cannot access to my dummyData variable
}
user1765862
  • 13,635
  • 28
  • 115
  • 220
  • that is not a global variable.In c# there is no global variables and if you define a variable inside of a method you cannot access it from outside of that method. – Selman Genç Mar 16 '14 at 10:20

1 Answers1

0

HttpContext.Items is accessible from global.asax, as well as from your controller. Please check this post for example:

HttpContext.Items with ASP.NET MVC

Community
  • 1
  • 1
Zygimantas
  • 8,547
  • 7
  • 42
  • 54