我得到這個錯誤:asp.net MVC 3剃鬚刀/ LINQ的
傳遞到字典的模型產品System.Data.Entity.Infrastructure.DbQuery``1[<>f__AnonymousType1``2[System.DateTime,System.Int32]]
類型,但是這本詞典需要System.Collections.Generic.IEnumerable``1[AtAClick.Models.WhatsOn]
型的典範項目。
這是我的控制器;
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);
}
我想在今天的日期和條目數之後返回所有條目。我對此很陌生,任何幫助都非常感謝!在此先感謝,如果您需要任何mjore細節,請讓我知道。謝謝!
這是我的視圖
==============================
@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>
}
= ===========================
這是我的控制器中的編輯方法;
// // GET:/ WhatsOn /編輯/ 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);
}
你能編輯你的文章幷包含你的視圖的代碼嗎? – Jon
是的,我現在將它彈出...完成。編輯hasd拿出了表格標籤。它實際上有點令人費解,但是其中的foreach就在那裏。 – Dan