ASP.net MVC プロジェクトに取り組んでおり、セッションを通じて ID として取得した特定のユーザー データを表示したいと考えています。その ID に従って、特定の従業員のすべてのデータを抽出したいと考えています。そのために、私はこのコードを実行しました:
私のコントローラーの Index メソッド:
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'.
私は今どうすればいい?