Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6233133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:14:36+00:00 2026-05-24T10:14:36+00:00

I keep getting this error for my project. The model item passed into the

  • 0

I keep getting this error for my project.

The model item passed into the dictionary is of type
‘System.Collections.Generic.List1[<>f__AnonymousType22[System.String,System.String]]’,
but this dictionary requires a model item of type
‘System.Collections.Generic.IEnumerable`1[ETMS.Models.DB.tblParent]’.

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

==================================================================================

What i want to do is to retrieve the data from the database (one to many) , This is my database table structure

tblparent
- Parent_ID
- Username
- Password
- Firstname
- Lastname

and

tblParentEmail
- ParentEmail_ID
- Email
- Parent_ID

i was made the foreign relation from email to parent, but i could not include with EF while there is another error. i do in this way and caused me this error :

public ActionResult Clientlist()
{
    using (ETMSPeopleEntities db = new ETMSPeopleEntities())
    {
        //var sxc = db.tblParents.Include("tblLocation").Include("tblParentEmails.ParentEmail_ID")
        //    .OrderByDescending(p => p.Status).ToList();
        var members = (from x in db.tblParentEmails
                      join y in db.tblParents
                      on x.Parent_ID equals y.Parent_ID 
                      select new { Email = x.ParentEmail, UserName = y.Username }).AsEnumerable();
        return View(members.ToList());
    }
}

This is my admincontroller

@model IEnumerable<ETMS.Models.DB.tblParent>
@{
    ViewBag.Title = "Clientlist";
}

<h2>Clientlist</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            Username
        </th> 
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr> 
        <td>
            @Html.DisplayFor(modelItem => item.Username)
        </td>
         <td>
            @Html.DisplayFor(modelItem => item.Firstname)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Lastname)
        </td>
          <td>
            @Html.DisplayFor(modelItem => item.Location_ID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Email)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.CreateTime)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.Parent_ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.Parent_ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.Parent_ID })
        </td>
    </tr>
}

</table>

this is clientlist view

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:14:38+00:00Added an answer on May 24, 2026 at 10:14 am

    You’re passing a list of anonymous objects to your view:

    select new { Email = x.ParentEmail, UserName = y.Username }
    

    While the view is expecting IEnumerable<ETMS.Models.DB.tblParent>:

    @model IEnumerable<ETMS.Models.DB.tblParent>
    

    You should change your selection to:

    select y
    

    in order for the code to work.

    Update

    Here is how you could use a view model pattern. First, create a view model class, so you’re not passing an anonymous type to your view. Let’s call it AwesomeEmailViewModel, and it looks like you need .Email, .Username and some other properties, so we’ll set those up too.

    public class AwesomeEmailViewModel
    {
        public string Email { get; set; }
        public string Username { get; set; }
        public string FirstName{ get; set; }
        public string LastName { get; set; }
        public int Location_ID{ get; set; }
        public DateTime CreateTime { get; set; }
    }
    

    Now, modify your query by using object initialization to populate an instance of AwesomeEmailViewModel

    Note: I am guessing which properties belong to which objects (either tblParent or tblParentEmails, so you will need to double-check these

    var members = (from x in db.tblParentEmails
                   join y in db.tblParents
                   on x.Parent_ID equals y.Parent_ID 
                   select new AwesomeEmailViewModel()
                   { 
                       Email = x.ParentEmail, 
                       UserName = y.Username,
                       FirstName = y.FirstName,
                       LastName = y.LastName,
                       Location_ID = x.Location_ID,
                       CreateTime = y.CreateTime, 
                   }).ToList();
                   // I don't know if you'll need the `AsEnumerable()` call
    
    return View(members);
    

    Finally, your view has to know what type(s) to expect, so let’s modify it to expect a list of our newly created AwesomeEmailViewModel instances.

    @model IEnumerable<ETMS.Models.AwesomeEmailViewModel>
    

    Pay close attention, as I guessed at the namespace as well. In any case, this should give you access to the properties you need inside your view. If you need more, you’ll need to modify the new view model class we created as well as the query in your controller action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
I keep getting this error, although the file still gets moved into the correct
I keep getting this error after cloning a repository from the AndEngine project.. The
I keep getting this when trying to start a new project ERROR: Unable to
I keep getting this error when I try to commit a group of executed
I keep getting this error when I try to call Find() public void findTxt(string
I keep getting this error all over the place where I only have jquery
I keep getting this error whenever I call gethostbyname() in my C code. ==7983==
I keep getting this error in Matlab: Attempted to access r(0,0); index must be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.