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 8988399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:00:22+00:00 2026-06-15T22:00:22+00:00

I know this is something simple but I can’t figure it out :( I’m

  • 0

I know this is something simple but I can’t figure it out 🙁

I’m receiving this error:

The model item passed into the dictionary is of type ‘System.Collections.Generic.List1[<>f__AnonymousType35[System.String,System.String,System.String,System.Nullable1[System.DateTime],System.String]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[MvcApplication3.Order]’.

Here is the code for my controller:

    var query = from o in db.Orders
                join c in db.Customers on o.CustomerID equals c.CustomerID
                where o.CustomerID == q
                select new
                {
                    o.CustomerID,
                    o.ShipAddress,
                    o.ShipCity,
                    o.ShippedDate,
                    c.ContactName
                };

    /*
    var query = from o in db.Orders
                where o.CustomerID == q
                select o;
    */
    return View(query.ToList());

Here is my view:

@model IEnumerable<MvcApplication3.Order>


@{
    ViewBag.Title = "Search";
}

<h2>Search</h2>
Your search results contains @Model.Count() rows

<table>
    <tr>
        <td>Customer ID</td>
        <td>Address</td>
        <td>City</td>
        <td>Shipped to Date</td>
    </tr>
@foreach (var item in Model)
{
    <tr>
        <td>@item.CustomerID</td>
        <td>@item.ShipAddress</td>
        <td>@item.ShipCity</td>
        <td>@item.ShippedDate</td>
        <td>@item.Customer.ContactName</td>

    </tr>
}
</table>

I’m assuming it has something to do with the way View is setup. If I remove the return View() and just loop through the data from the controller I get the results I expect. Any help would be greatly appreciated.

Thanks in advance!

  • 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-06-15T22:00:23+00:00Added an answer on June 15, 2026 at 10:00 pm

    EDIT:

    Try this:

    select new Order()
                        {
                            CustomerId = o.CustomerID,
                            ShipAddress = o.ShipAddress,
                            ShipCity = o.ShipCity,
                            ShippedDate = o.ShippedDate,
                            Customer = new Customer()
                                  {
                                     ContactName = c.ContactName
                                  }
                        };
    

    You didn’t specify the model. You created a List of anonymous objects, and the view is expecting an IEnumerable<Order>.

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

Sidebar

Related Questions

I know this is probably something simple, but I can't figure it out. When
I know this must be very simple. But I can't figure it out. I
I know this is probably something simple but I can't seem to find anything
this should be really simple but I can just not figure it out at
I know I am missing something simple, but I can't get this redirect to
This is something really simple, but I can't seem to find the answer anywhere,
I know this is a really simple thing in obj-c, but I can't seem
I know I am missing something simple but I can't seem to get my
I know this is supposed to be simple, but I'm running into multiple problems.
I must be overlooking something very simple here but I can't seem to figure

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.