How to separate ViewBag information that is common to multiple Controllers?

86 views Asked by At

I do this in everyone of my Controllers, including those in separate controller files. The reason is that this is the viewbag information I need for my layout. How can I separate this out of all my 10-20 controller classes, to a separate function that can be referenced by each controller, even those in other controller files.

    public ActionResult CompanyDashboard(string CompanyName, int ProjectNumber = 0) {
        UserBAL u = new UserBAL();
        Users use = u.GetUser();
        ViewBag.Username = use.Username;
        ViewBag.Domain = use.Domain;
        ViewBag.Company = use.Company;

        ProjectsBAL d = new ProjectsBAL();
        Projects e = d.GetProject(ProjectNumber);
        ViewBag.ProjectNumber = e.ProjectNumber;
        ViewBag.ProjectName = e.ProjectName;
        ViewBag.CompanyName = e.CompanyName;
        ViewBag.ClientName = e.ClientName;

        List<Projects> g = d.GetProjects();
        ViewBag.ProjectsData = g;

        ViewBag.DateTime = System.DateTime.Now;

        return View("CompanyDashboard");
    }
0

There are 0 answers