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
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);
}