在我的控制器类中,我有一个私有方法,它返回使用 User.Identity.Name 作为参数获取的登录用户,这一切都很好。
private static Account GetLoggedUser()
{
AccountService accService = new AccountService();
Account userAccount = accService.GetAccountByUsername(User.Identity.Name);
return userAccount;
}
public ActionResult Edit()
{
var userAccount = GetLoggedUser();
...
}
问题是我在线收到此错误User.Identity.Name
非静态字段、方法或属性“System.Web.Mvc.Controller.User.get”需要对象引用
编译时显示错误。