我不知道这个错误发生了什么:
@H_404_2@传入字典的模型项目的类型为“System.Collections.Generic.List1 [RepositoryExample.Employee]”,但是该字典需要一个类型为“RepositoryExample.Models.IEmployeeManagerRepository”的模型项.
@H_404_2@当我转到索引视图时,我收到错误.我从控制器添加了索引视图,但没有代码.我使用Linq到sql.
@model RepositoryExample.Models.IEmployeeManagerRepository @{ ViewBag.Title = "Index"; } <h2>Index</h2>@H_404_2@这是我的代码: @H_404_2@EmployeeController.cs
// GET: /Employee/ public ActionResult Index() { return View(_repository.ListEmployees()); }@H_404_2@LinqEmployeeManagerRepository.cs
public class LinqEmployeeManagerRepository: RepositoryExample.Models.IEmployeeManagerRepository { private DeptDirectoryDataClassesDataContext _db = new DeptDirectoryDataClassesDataContext(); public Employee GetEmployee(string UserName) { return (from e in _db.Employees where e.UserName == UserName select e).FirstOrDefault(); } public IEnumerable<Employee> ListEmployees() { return _db.Employees.ToList(); } public Employee CreateEmployee(Employee employeeToCreate) { _db.Employees.InsertOnSubmit(employeeToCreate); _db.SubmitChanges(); return employeeToCreate; } public Employee EditEmployee(Employee employeeToEdit) { var OriginalEmployee = GetEmployee(employeeToEdit.UserName); _db.Employees.Attach(employeeToEdit,OriginalEmployee); _db.SubmitChanges(); return employeeToEdit; } public void DeleteEmployee(Employee employeeToDelete) { var OriginalEmployee = GetEmployee(employeeToDelete.UserName); _db.Employees.DeleteOnSubmit(OriginalEmployee); _db.SubmitChanges(); } }@H_404_2@IEmployeeManagerRepository.cs
namespace RepositoryExample.Models { public interface IEmployeeManagerRepository { Employee CreateEmployee(Employee employeeToCreate); void DeleteEmployee(Employee employeeToDelete); Employee EditEmployee(Employee employeeToUpdate); Employee GetEmployee(string UserName); IEnumerable<Employee> ListEmployees(); }@H_404_2@} @H_404_2@任何想法我做错了什么?我试图按照本教程中的Repository模式的例子(http://www.asp.net/mvc/tutorials/iteration-4-make-the-application-loosely-coupled-cs)