gurehbgui gurehbgui - 1 year ago 119
ASP.NET (C#) Question

How to create a BaseController with a ViewBag

I need to do the following:
I have some Controllers ready and running, but now I want to create a

Each of my
should inherit from it like this:

public class MySecondController : BaseController

thats already running so far. Now the Problem:

I want to add a
into this base controller. This
should be accessable from every view which is called in my controllers.

How to realise this?

Answer Source

You can override OnActionExecuting method in the overridden method you can data to ViewBag dictionary.

public class BaseController : Controller
    protected override void OnActionExecuting(ActionExecutingContext filterContext)
        ViewBag.someThing = "someThing"; //Add whatever
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download