Click here to Skip to main content
15,946,074 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my Model
C#
public class ContactsModel
    {
        public int? ContactID { get; set; }
        public string ContactName { get; set; }
        public string EMailID { get; set; }
        public int? CountryID { get; set; }
        public int? StateID { get; set; }
        public long? ContactNumber { get; set; }
    }


This is my Interface:
XML
public interface IContactsRepository
   {
       IEnumerable<ContactsModel> GetAllContactDetails();

   }


This is my RepositoryClass
XML
public class ContactsRepository:IContactsRepository
   {
       private List<ContactsModel> contacts = new List<ContactsModel>();
       private int _nextId = 1;
       DGKumarEntities objEntity = new DGKumarEntities();

       public ContactsRepository()
       {

       }

       public IEnumerable<ContactsModel> GetAllContactDetails()
       {
           var contactDet = (from det in objEntity.tblContactDetails
                             select new ContactsModel
                             {
                                 ContactID = det.ContactID,
                                 ContactName = det.ContactName,
                                 EMailID = det.EMailID,
                                 CountryID = det.CountryID,
                                 StateID = det.StateID,
                                 ContactNumber = det.ContactNumber
                             });
           return contactDet;
       }
   }

This is my Controller
C#
private readonly IContactsRepository objIContactRepository = new ContactsRepository();

       public ActionResult Index()
       {
           var contactDetailsResult = objIContactRepository.GetAllContactDetails();

           return View(contactDetailsResult);
       }


This is my My

@model MyContactsRepositoryPattern.Models.ContactsModel

when i tried to create the strongly Typed view it will not display data and this error is displaying.

"The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MyContactsRepositoryPattern.Models.ContactsModel]', but this dictionary requires a model item of type 'MyContactsRepositoryPattern.Models.ContactsModel'."


So could you please suggest me how can i resolve this and which one do i have to select do display data in strongly typed view from dropdownlist of model List
Posted
Updated 28-May-14 21:05pm
v2

how did you declare model in view page??
can you post your view page source code?
 
Share this answer
 
Comments
DGKumar 29-May-14 3:03am    
I have mentioned like this
@model MyContactsRepositoryPattern.Models.ContactsModel
@model MyContactsRepositoryPattern.Models.ContactsModel instead of
declare like this
@model IEnumerable <'location of model'>
 
Share this answer
 
v3
Comments
DGKumar 29-May-14 3:19am    
Thank you very much now it is working fine.
Murali Vijay 29-May-14 3:22am    
it's ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900