string currentUserId = User.Identity.GetUserId();
var us = from u in db.Users
join s in db.Designations
on new { id = u.DesignationID } equals new { id = s.DesignationID }
where u.Id == currentUserId
select new ViewEmployees
{
EmployeeCode = u.UserName,
EmployeeName = u.Name,
Father_Name = u.Father_Name,
DesignationName = s.DesignationName,
EmployeeType = u.EmployeeType,
Email = u.Email,
Mobile = u.Mobile
};
我想使用它的输出作为另一个视图的部分视图…我该如何为它写控制器?ActionResult或其他....?
你可以将你的值传递给partialview,首先给出路径,然后传递你的模型,并在partialview中绑定相关的模型!
public ActionResult YourMethodName()
{
ViewEmployees us = from u in db.Users
join s in db.Designations
on new { id = u.DesignationID } equals new { id = s.DesignationID }
where u.Id == currentUserId
select new ViewEmployees
{
EmployeeCode = u.UserName,
EmployeeName = u.Name,
Father_Name = u.Father_Name,
DesignationName = s.DesignationName,
EmployeeType = u.EmployeeType,
Email = u.Email,
Mobile = u.Mobile
};
return PartialView("~/PartialViewName", us);
}
和你的局部视图
@model eHRManager.Models.ViewEmployees