通过UserId获取UserName并显示在视图中



. NET MVC 5应用程序如何从给定的UserId中获取Username并将其显示在View中?

注意-我不需要电流 UserUsername

根据您的评论,您正在使用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;

最新更新