views:

59

answers:

1

i having error throw on View page and i think i am passing wrong type, can anybody please correct me - thanks.

The model item passed into the dictionary is of type '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 looks like this....

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 look like this...

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<IEnumerable<App.Domain.Service.PersonService>>" %>

my controller look like this...

 public ActionResult GetPersons()
        {
            IPersonRepository personRepo = new PersonRepository();
            PersonService person = new PersonService(personRepo);
            IList<IPerson> p  = person.GetPerson(); 
            return View(p);
        }
+2  A: 

You are sending the wrong type to the View() In your View decleration says App.Domain.Service.PersonService, but in your View you are sending it a View(IPerson). If you want to send an IPerson to your view the tag should read like:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<App.Domain.Model.Interface.IPerson>>" %> 
Anthony
why i dont see the "App.Domain.Model.Interface.IPerson" in view data class? means...when i create a View page (right click in the controller and click on Add View) and i select "create strongly typed view" but i see all my model/repository classes but i dont see anything related with "Interface" why is that?
Abu Hamzah
Not really sure why they dont include Interfaces, I actually haven't tried to use one through the view wizard before.That would be a good follow up question though.
Anthony