我正在开发一个 ASP.net MVC 项目,并希望显示我通过会话获得的特定用户数据。根据该 ID,我想提取特定员工的所有数据。为此我做了这个代码:
我的控制器的索引方法:
public ActionResult Index()
{
object s = Session["EmployeeID"];
var sessval = s.ToString();
AdminDetailsModel model = new AdminDetailsModel();
var data1 = (from e in db.Employees.Where(c => c.EmployeeID == sessval) join d in db.Designations on e.Designation1up equals d.Designation1up select new { EmployeeID = e.EmployeeID, FirstName = e.FirstName, LastName = e.LastName, DesignationInternal = d.DesignationInternal, DesignationExternal = d.DesignationExternal, OfficePhone = e.OfficePhone, CellPhone = e.CellPhone, JoiningDate = e.JoiningDate, EmailID = e.EmailID, Address = e.Address }).SingleOrDefault();
return View(data1);
}
我为此创建了视图模型,其中我采用了我需要在视图中显示的所有方法。
我已经创建了这个方法的视图,它在我的模型类上是强类型的。当我运行它时,出现以下错误:
System.InvalidOperationException: The model item passed into the dictionary is of type '<>f__AnonymousType1`10[System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.DateTime,System.String,System.String]', but this dictionary requires a model item of type 'ResourceTracking.Employee'.
我现在该怎么办?