Asp.net mvc 在MVC Razor视图中返回用户全名而不是用户ID
我试图在我的视图中显示用户的全名,而不是Asp.net mvc 在MVC Razor视图中返回用户全名而不是用户ID,asp.net-mvc,razor,Asp.net Mvc,Razor,我试图在我的视图中显示用户的全名,而不是ID。所以在我的 modelView public int UserId { get; set; } public string FullName {get;set;} 但在我看来,我想显示全名,比如“Joe Doe” 有人能帮我在你的模型视图中添加一个名为全名的字符串属性吗 modelView public int UserId { get; set; } public string FullName {get;set;} 然后通过控制器上的Us
ID
。所以在我的
modelView强>
public int UserId { get; set; }
public string FullName {get;set;}
但在我看来,我想显示全名,比如“Joe Doe”
有人能帮我在你的
模型视图中添加一个名为全名的字符串属性吗
modelView强>
public int UserId { get; set; }
public string FullName {get;set;}
然后通过控制器上的UserID
获取您的用户
public ActionResult Index(){
User User = DbContext.User.Where(x => x.UserID == something).FirstOrDefault(); // gets the user by ID
modelView model= new modelView();
model.FullName = User.Name + " " + User.LastName; // set Full name
return View(model); // return model to razor
}
希望有帮助