如何从 AspNetCore 中的 linq 查询中读取值?
How can can i read values from linq query in AspNetCore?
var userData = from x in _context.UserAccount.Where(x => x.UserName == login.UserName)
select new { x.UserFullName, x.Email, x.UserAddress ,x.UserName
,x.UserPhoto ,x.UserMobileNo,x.UserGender,x.UserQualification,
x.UserDepartment,x.UserDesignation,x.UserPriviledge,x.UserAccountId};
TempData["userData"] = JsonConvert.SerializeObject(userData);
如何从 userData
中读取值?然后存储在 TempData
中以传递到下一个视图?请帮忙!谢谢!!
您应该像下面这样创建 UserViewModel
public class UserViewModel
{
public string UserFullName {get; set; }
public string Email {get; set; }
public string UserAddress {get; set; }
// The rest of properties
}
然后你可以select这样的结果
var userData = (from x in _context.UserAccount.Where(x => x.UserName == login.UserName)
select new UserViewModel
{
UserFullName = x.UserFullName,
Email = x.Email,
UserAddress = x.UserAddress
// The rest of properties
}).ToList();
TempData["userData"] = userData;
最后,在View
你可以这样
@{
var userData = TempData["userData"] as List<UserViewModel>; // Make sure you've already included _NameSpace_Of_UserViewModel
}
var userData = from x in _context.UserAccount.Where(x => x.UserName == login.UserName)
select new { x.UserFullName, x.Email, x.UserAddress ,x.UserName
,x.UserPhoto ,x.UserMobileNo,x.UserGender,x.UserQualification,
x.UserDepartment,x.UserDesignation,x.UserPriviledge,x.UserAccountId};
TempData["userData"] = JsonConvert.SerializeObject(userData);
如何从 userData
中读取值?然后存储在 TempData
中以传递到下一个视图?请帮忙!谢谢!!
您应该像下面这样创建 UserViewModel
public class UserViewModel
{
public string UserFullName {get; set; }
public string Email {get; set; }
public string UserAddress {get; set; }
// The rest of properties
}
然后你可以select这样的结果
var userData = (from x in _context.UserAccount.Where(x => x.UserName == login.UserName)
select new UserViewModel
{
UserFullName = x.UserFullName,
Email = x.Email,
UserAddress = x.UserAddress
// The rest of properties
}).ToList();
TempData["userData"] = userData;
最后,在View
你可以这样
@{
var userData = TempData["userData"] as List<UserViewModel>; // Make sure you've already included _NameSpace_Of_UserViewModel
}