1
我在查看页面上出现错误,并且我认为我传递错误类型,是否有人请纠正我 - 谢谢。传入字典的模型项目类型为{ASP.NET MVC}
传递到字典中的模型项类型为'System.Collections.Generic.List 1[App.Domain.Model.Interface.IPerson]' but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [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);
}
为什么我没有看到“App.Domain.Model.Interface.IPerson”鉴于数据类?意味着...当我创建一个视图页面(右键单击控制器,然后单击添加视图),我选择“创建强类型视图”,但我看到我所有的模型/存储库类,但我没有看到任何与“接口”这是为什么? – 2010-06-30 17:58:36
不知道为什么他们不包括接口,我实际上没有尝试过使用视图向导之前。 虽然这将是一个很好的后续问题。 – Anthony 2010-06-30 19:56:24