MVC error - The model item passed into the dictionary is of type 'System.Collections.Generic.List`

后端 未结 1 720
情书的邮戳
情书的邮戳 2021-02-08 06:15

I can\'t figure out what\'s going on with this error:

The model item passed into the dictionary is of type \'System.Collections.Generic.List1[Repository

相关标签:
1条回答
  • 2021-02-08 06:52

    In the top of your Index.cshtml view replace:

    @model RepositoryExample.Models.IEmployeeManagerRepository
    

    with:

    @model IEnumerable<RepositoryExample.Employee>
    

    The _repository.ListEmployees() method returns IEnumerable<Employee> and that's what you are passing to the view here:

    return View(_repository.ListEmployees());
    

    So that's the type you should be using in the @model directive in your view.

    0 讨论(0)
提交回复
热议问题