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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:27:31+00:00 2026-06-05T16:27:31+00:00

Got this error message while trying to load view: The model item passed into

  • 0

Got this error message while trying to load view:

The model item passed into the dictionary is of type
'System.Data.Entity.Infrastructure.DbQuery`1[<>f__AnonymousType0`2[System.Int32,System.String]]',
but this dictionary requires a model item of type
'System.Collections.Generic.IEnumerable`1[HelloWorld.Models.P]'.

Could it be from not passing the correct type from the Controller to the View?

Here’s the model:

public class P
{
    [Key]
    public virtual int ImportID { set; get; }
    public virtual string MicroName { set; get; }
}

Here’s the DBContext definition:

public DbSet<P> Ps { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
  //REMAPPING TABLE NAMES 
  modelBuilder.Entity<P>()
.ToTable("SomeTable_With_Really_LongName_tbl");

base.OnModelCreating(modelBuilder);
}

Here’s the Controller action:

public ActionResult ListP()
{

var model = (from p in _db.Ps
 select new
 {
p.ImportID,
 p.MicroName
 }).Take(10);

return View(model);
}

Here’s the view:

@model IEnumerable<HelloWorld.Models.P>

@{
    ViewBag.Title = "List P";
}

<h2>List P</h2>

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

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ImportID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.MicroName)
        </td>
        <td>
        @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
        @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
        @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
    </td>
</tr>
}

</table>

Any ideas?

  • 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-05T16:27:33+00:00Added an answer on June 5, 2026 at 4:27 pm

    think that

    var model = (from p in _db.Ps
     select new
     {
    p.ImportID,
     p.MicroName
     }).Take(10);
    

    is returning the Import ID and Name where it should be returning a enumerator of P

    var model = _db.Ps.OrderBy(f => f.[FieldName]).Take(10);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got this error message while trying to configure an entitydatasource in the designer: My
I got this error while trying to get facebook access_token from node.js server: {error:{message:(#803)
i got this error while trying to rebind a grid: ( Parent page (
I got this error messages while I am trying to deploy my django app
I got this error message while querying the top 50 row in a table.
I got this error message and I'm not quite sure whats wrong: Exception in
I got this error from XCode: objc[8422]: FREED(id): message release sent to freed object=0x3b120c0
I got this error An error occurred while parsing EntityName. Line 1, position 61.
I have got an error while trying to upgrade our large project to SL4.
I'm getting a key not found error message while trying to start my Play

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.