Additional information in ASP.Net MVC View

Posted by Max Malmgren on Stack Overflow See other posts from Stack Overflow or by Max Malmgren
Published on 2010-06-14T12:11:49Z Indexed on 2010/06/14 12:22 UTC
Read the original article Hit count: 148

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc