我在我的每个控制器中执行此操作,包括在单独的控制器文件中。原因是这是我的布局所需的viewbag信息。如何将我的所有10-20控制器类中的这一个分离到一个可以被每个控制器引用的单独函数,甚至是其他控制器文件中的函数。
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");
}