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

  • Home
  • SEARCH
  • 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 6124085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:05:33+00:00 2026-05-23T16:05:33+00:00

I’m getting this error: The model item passed into the dictionary is of type

  • 0

I’m getting this error:

The model item passed into the dictionary is of type System.Data.Entity.Infrastructure.DbQuery``1[<>f__AnonymousType1``2[System.DateTime,System.Int32]], but this dictionary requires a model item of type System.Collections.Generic.IEnumerable``1[AtAClick.Models.WhatsOn].

This is my controller;

public ViewResult Index(WhatsOn model)
{       
   DateTime myDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

   var datequery =
            db.WhatsOns.Where(c => c.start > myDate).OrderByDescending(c => c.start).GroupBy(c => c.start).Select(
                sGroup => new
                              {
                                  day = sGroup.Key,
                                  whtscount = sGroup.Count()
                              });

   return View(datequery);
}

I want to return all entries after todays date and the number of entries. I’m new to this, any help is greatly apprecieted! Thanks in advance, if you need any mjore detail just let me know. Thanks!

This is my view

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

@model IEnumerable<AtAClick.Models.WhatsOn>

@{ ViewBag.Title = "Index"; }

<h2>Index</h2>

<p>@Html.ActionLink("Create New", "Create")</p>
<table>
    <tr>
        <th>start</th>
        <th>end</th>
        <th>Name</th>
        <th>Desc</th>
        <th>link</th>
        <th>CalenderDisplay</th>
        <th></th>
    </tr>

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

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

This is the edit method in my controller;

//
// GET: /WhatsOn/Edit/5

    public ActionResult Edit(int id)
    {
        WhatsOn whatson = db.WhatsOns.Find(id);
        return View(whatson);
    }

    //
    // POST: /WhatsOn/Edit/5

    [HttpPost]
    public ActionResult Edit(WhatsOn whatson)
    {
        if (ModelState.IsValid)
        {
            db.Entry(whatson).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(whatson);
    }
  • 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-23T16:05:33+00:00Added an answer on May 23, 2026 at 4:05 pm

    i think the problem is a mismatch between what your view expects and what your controller is passing.

    In your select statement your selecting a new anonymous type but your view is expecting the type IEnumerable<WhatsOn>

    assuming the whats on fields are day and whtscount then replace the datequery with

        var datequery =
            db.WhatsOns.Where(c => c.start > myDate).OrderByDescending(c => c.start).GroupBy(c => c.start).Select(
                sGroup => new WhatsOn()
                              {
                                  day = sGroup.Key,
                                  whtscount = sGroup.Count()
                              });
    

    Update:
    The error is indicating that your select query cannot be translated into the equivilent sql, what you could try is changing it to

        var datequery =
            db.WhatsOns.Where(c => c.start > myDate).OrderByDescending(c => c.start).GroupBy(c => c.start).AsEnumerable().Select(
                sGroup => new WhatsOn
                              {
                                  day = sGroup.Key,
                                  whtscount = sGroup.Count()
                              });
    

    Update: I think the issue may be that when you get to the post method of the edit, the WhatsOn object is no longer associated with the database WhatsOn it was originally loaded from, have a go at changing it to

    public ActionResult Edit(int id)
    {
        WhatsOn whatson = db.WhatsOns.Find(id);
        return View(whatson);
    }
    
    [HttpPost]
    public ActionResult Edit(int id, FormCollection collection)
    {
        WhatsOn whatsOnmodel = db.WhatsOns.Find(id);
    
        if (TryUpdateModel(whatsOnmodel))
        {
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(whatsOnmodel );
    }
    

    Update: If that approach was not working you could see if your one did just add the loading at the beginning so

    [HttpPost]
    public ActionResult Edit(int id, WhatsOn whatson)
    {
        WhatsOn whatsOnmodel = db.WhatsOns.Find(id);
    
        if (ModelState.IsValid)
        {
            whatsOnmodel.day = whatson.day;
            whatsOnmodel.whtscount = whatson.whtscount;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(whatsOnmodel);
    }
    

    you could test that and see what happens

    Update:
    Actually i think your first approach should of worked but i think it requires the Id, what happens if you make it

    [HttpPost]
    public ActionResult Edit(int id, WhatsOn whatson)
    {
        if (ModelState.IsValid)
        {
            db.Entry(whatson).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(whatson);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't 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.