asp.net mvC语言 如何为分部视图编写操作


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

相关内容

  • 没有找到相关文章

最新更新