I would suggest that you can perform a child action and call it from the layout. Thus, you can avoid the execution of information in all viewing models.
Ref.
Action for children
public class UserController
{
[ChildActionOnly]
public PartialViewResult UserInfo()
{
var userInfo = .. get the user information from session or db
return PartialView(userInfo);
}
}
Partial view
@model UserInfoModel
@Html.DisplayFor(m => m.UserName)
@Html.DisplayFor(m => m.CompanyName)
...
Layout view
<header>
@Html.Action("UserInfo", "User")
</header>
source
share