Where to declare(Application variable) and How to access application variable in controller ?
How to get model(model.tt file) value from database in application_start() ?
i don't have any idea about application variable, So if you know anything about it then help me.
Thanks..!
Asked
Active
Viewed 3,962 times
2

Smit Kotadia
- 21
- 1
- 6
-
no , in this question there is no any answer like where to declare or how to access in controller. – Smit Kotadia Apr 12 '18 at 05:18
-
Possible duplicate of [Does asp.net MVC have Application variables?](https://stackoverflow.com/questions/2266533/does-asp-net-mvc-have-application-variables) – Claies Apr 12 '18 at 05:20
-
how could you suggest this isn't a duplicate? Is this not the exact answer you are looking for? https://stackoverflow.com/a/42222894/2495283 – Claies Apr 12 '18 at 05:20
-
but, it won't work.i already do it. – Smit Kotadia Apr 12 '18 at 05:22
-
is there any alternate way , then suggest me. – Smit Kotadia Apr 12 '18 at 05:23
-
If it does not work please show us your code so we can see and verify it – dsdel Apr 12 '18 at 05:30
-
Company won't give permission to us. – Smit Kotadia Apr 12 '18 at 06:20
1 Answers
0
In global.asax file first declare service in which you write linq syntax or your logic,
private readonly ISystemConfigurationService _systemConfigurationService;
Then, create constructor
public MvcApplication()
{
_systemConfigurationService = new SystemConfigurationService();
}
Get Model Data when app start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
List<SystemConfigurationModel> systemConfigurationValue = General.MapList<System_Configuration , SystemConfigurationModel> (_systemConfigurationService.GetAllSystemConfigData());
Application["SystemConfig"] = new List<SystemConfigurationModel>(systemConfigurationValue);
}
In controller you have to do this,
List<SystemConfigurationModel> applicationState = HttpContext.Application["SystemConfig"] as List<SystemConfigurationModel>;
ViewBag.ContactEmail = applicationState.Find(x => x.Config_Key == "ContactMail").Value;
Then Pass it to view using view bag.

Smit Kotadia
- 21
- 1
- 6