Passing contextual info to Views in ASP.NET MVC

Posted by Andrey on Stack Overflow See other posts from Stack Overflow or by Andrey
Published on 2010-05-25T07:01:42Z Indexed on 2010/05/25 7:31 UTC
Read the original article Hit count: 186

Filed under:
|

I wonder - what is the best way to supply contextual (i.e. not related to any particular view, but to all views at the same time) info to a view (or to master page)?

Consider the following scenario.

Suppose we have an app that supports multiple UI languages. User can switch them via UI's widgets (something like tabs at the top of the page). Each language is rendered as a separate tab. Tab for the current language should not be rendered.

To address these requirements I'm planning to have a javascript piece that will hide current's language tab on the client. To do this, I need current's language tab Id on the client. So, I need some way of passing the Id to master page (for it to be 'fused' into the js script).

The best thing I can think of is that all my ViewModels should inherit some ViewModeBase that has a field to hold current language tab Id. Then, whatever View I'm rendering, this Id will always be available for the master page's hiding script.

However, I'm concerned that this ViewModelBase can potentially grow in an uncontrolled fashion as number of such pieces of contextual info (like current language) will grow..

Any ideas?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about viewmodel