0

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");
    }
slugster
  • 49,403
  • 14
  • 95
  • 145
gunslingor
  • 1,358
  • 12
  • 34
  • i'd actually create a separate partial view with it's own view model and call the partial view in your layout – Fran Jan 05 '17 at 21:12
  • 1
    Why you using ViewBag in excessive size? ViewBag is just for limited use and in very rare cases. Try to use strongly type views which suits to your view. – Hadee Jan 05 '17 at 21:19

0 Answers0