I have a custom authenticantion, when user logs in, I keep the necessary information on Session/Cache...
So, I have some Views with DropDowns that must show data fil
I would just create an action filter that puts the values you need inside a ViewBag and send it over to the view. This way you don't have to rewrite the same code over and over again and you can just concentrate on the view to display the data as necessary. Please see below for sample code:
using System.Web.Mvc;
namespace CustomActionFilter.CustomActionFilters
{
public class MyResultFilterAttribute : FilterAttribute, IResultFilter
{
public void OnResultExecuting(ResultExecutingContext filterContext)
{
//The action filter logic - before
filterContext.Controller.ViewBag.userInfo = GetNeccUserInfo(filterContext.HttpContext.User.Identity.Name);
}
public void OnResultExecuted(ResultExecutedContext filterContext)
{
//The action filter logic - after
}
}
private UserInfo GetNeccUserInfo(string userName)
{
using (var repo = new UserRepository(new UniteOfWorkUsers()))
{
var userInfo = repo.GetUserInfo(userName);
return userInfo;
}
}
}
Hope this helps out :)