when click edit link in index page
it give me error
The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Employee_2EF71CC17A29BA91B02BC5CDB0EE5AF82D363EEF7E174A21C9546772913AA929', but this dictionary requires a model item of type 'WebCourse.Models.Customemployee'.
I have custom model
- namespace WebCourse.Models Customemployee
- {
- public class Customemployee
- {
- public string Name { get; set; }
- public int Salary { get; set; }
- public string Email { get; set; }
- public int DistrictId { get; set; }
-
- public List<EmployeeCourse> Courses { get; set; }
- public List<EmployeeLangage> Langs { get; set; }
- }
-
- }
and my controller empcourse
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using WebCourse.Models;
- using System.Data.Entity;
- namespace WebCourse.Controllers
- {
- public class empcourseController : Controller
- {
- mycourseEntities db = new mycourseEntities();
-
- public ActionResult Index()
- {
- var query = db.Employees.ToList().Select(p => new EmpInfo
- {
- Id = p.Id,
- Name = p.Name,
- Salary = Convert.ToInt32( p.Salary),
- Email = p.Email,
- DistrictName = p.Destrict.DistrictName,
- CityName = p.Destrict.City.CityName,
- CountryName = p.Destrict.City.Country.CountryName,
- CourseNames = p.EmployeeCourses.Select(t => t.Course.CourseName).ToList(),
- LanguageName = p.EmployeeLangages.Select(t => t.Language.LnaguageName).ToList(),
- levelName = p.EmployeeLangages.Select(t => t.Level.LevelName).ToList(),
- CourseName = string.Join(",", p.EmployeeCourses.Select(t => t.Course.CourseName).ToList())
- });
-
- return View(query);
- }
- public ActionResult Create()
- {
- ViewBag.CountryId = new SelectList(db.Countries, "Id", "CountryName");
- ViewBag.LanaguageId = new SelectList(db.Languages.ToList(), "Id", "LnaguageName");
- ViewBag.LevelId = new SelectList(db.Levels.ToList(), "Id", "LevelName");
- ViewBag.CourseId = new SelectList(db.Courses.ToList(), "Id", "CourseName");
- return View();
- }
- public ActionResult Edit(int id)
- {
-
- Employee old = db.Employees.Find(id);
- return View(old);
- }
- [HttpPost]
- public ActionResult Create(Customemployee cemp)
- {
-
- using (mycourseEntities db = new mycourseEntities())
- {
- Employee E = new Employee { Name = cemp.Name, Salary = cemp.Salary, Email = cemp.Email, DistrictId = cemp.DistrictId };
- foreach (var i in cemp.Courses)
- {
-
- E.EmployeeCourses.Add(i);
- db.SaveChanges();
- }
- foreach (var i in cemp.Langs)
- {
-
- E.EmployeeLangages.Add(i);
- db.SaveChanges();
- }
- db.Employees.Add(E);
- db.SaveChanges();
- }
- return View();
- }
- public JsonResult getcitybyid(int id)
- {
- db.Configuration.ProxyCreationEnabled = false;
- return Json(db.Cities.Where(a => a.CountryId == id), JsonRequestBehavior.AllowGet);
- }
- public JsonResult getdistrictbyid(int id)
- {
- db.Configuration.ProxyCreationEnabled = false;
- return Json(db.Destricts.Where(a => a.CityId == id), JsonRequestBehavior.AllowGet);
- }
- }
- }