. NET MVC 5应用程序如何从给定的UserId
中获取Username
并将其显示在View
中?
注意-我不需要电流 User
的Username
。
根据您的评论,您正在使用ASP。净的身份。我假设你已经有了ApplicationUserManager。例如
private ApplicationUserManager _userManager;
protected ApplicationUserManager UserManager
{
get { return _userManager ?? (_userManager =
HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>()); }
}
你可以调用FindById方法。
var user = UserManager.FindById(id);
string username = user.UserName;