抓取当前用户的OU并返回一个自定义模型(Division),该模型具有一些关于OU的属性。然后通过ViewBag传递它。我的控制器看起来像这样:
public ActionResult NewAccountRequest()
{
var currentUser = HttpContext.User;
var userDivision = ADTools.GetDivisionFromUser(currentUser.Identity.Name);
ViewBag.UserDivision = userDivision;
....
}
[HttpPost]
public ActionResult LookupUNI(string uni)
{
var currentUser = HttpContext.User;
var userDivision = ADTools.GetDivisionFromUser(currentUser.Identity.Name);
ViewBag.UserDivision = userDivision;
....
}
等
答案 0 :(得分:2)
如果这对您的所有操作都很常见,您可以将其添加到控制器的OnActionExecuted中。
public void override OnActionExecuted( ActionExecutedContext context )
{
if (context.Result is ViewResult)
{
var currentUser = HttpContext.User;
var userDivision = ADTools.GetDivisionFromUser(currentUser.Identity.Name);
ViewBag.UserDivision = userDivision;
}
}