【发布时间】:2010-06-30 15:55:24
【问题描述】:
我在查看页面上出现错误,我认为我传递了错误的类型,任何人都可以纠正我 - 谢谢。
传入字典的模型项的类型为“System.Collections.Generic.List1[App.Domain.Model.Interface.IPerson]' but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[App.Domain.Service.PersonService]”。
MyService 看起来像这样......
namespace App.Domain.Service
{
public class PersonService : IPersonService
{
private IPersonRepository _personRepository;
public PersonService(IPersonRepository personRepository)
{
_personRepository = personRepository;
}
public List<IPerson> GetPerson()
{
return _personRepository.GetHost();
}
}
}
myView 看起来像这样...
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<IEnumerable<App.Domain.Service.PersonService>>" %>
我的控制器看起来像这样...
public ActionResult GetPersons()
{
IPersonRepository personRepo = new PersonRepository();
PersonService person = new PersonService(personRepo);
IList<IPerson> p = person.GetPerson();
return View(p);
}
【问题讨论】:
标签: asp.net asp.net-mvc