Additional information in ASP.Net MVC View
- by Max Malmgren
I am attempting to implement a custom locale service in an MVC 2 webpage. I have an interface IResourceDictionary that provides a couple of methods for accessing resources by culture. This is because I want to avoid the static classes of .Net resources.
The problem is accessing the chosen IResourceDictionary from the views. I have contemplated using the ViewDataDictionary given, creating a base controller from which all my controllers inherits that adds my IResourceDictionary to the ViewData before each action executes.
Then I could call my resource dictionary this way:
(ViewData["Resources"] as IResourceDictionary).GetEntry(params);
Admittedly, this is extremely verbose and ugly, especially in inline code as we are encouraged to use in MVC. Right now I am leaning towards static class access
ResourceDictionary.GetEntry(params);
because it is slightly more elegant. I also thought about adding it to my typed model for each page, which seems more robust than adding it to the ViewData..
What is the preferred way to access my ResourceDictionary from the views? All my views will be using this dictionary.