I have created a Base-Controller from which all the controllers inherit. Currently this controller fills some data (which I use in most views) into the ViewData-Container like this:
    protected override void Initialize(System.Web.Routing.RequestContext rc)
    {
        base.Initialize(rc);
        ViewData["cms_configuration"] = new CmsConfiguration();
        // etc.
    }
I don't like the fact that I need to read (and cast) from ViewData within the views. I'd like to introduce a BaseViewModel from which all ViewModels will inherit from, defining the properties instead of using ViewData. But how or where can I populate the BaseViewModel within the BaseController? Is there some kind of hook? Or do I simply need to define a function in BaseController, which I call in the Child-Controller?
E.g. (Child-Controller:
//{...}
base.PopulateBaseView(MyView);
return View(MyView);
Thx for any tipps. sl3dg3
You could optionally use ActionFilters to do stuff like this:
Check out this article:
http://www.asp.net/mvc/tutorials/understanding-action-filters-cs
It explains ActionFilters nicely. That way you can separate different populate-logic into different filters, and turn them on and off as you please.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论