【发布时间】:2011-07-12 22:01:40
【问题描述】:
我收到此错误:
传入字典的模型项的类型为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/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);
}
【问题讨论】:
-
您可以编辑您的帖子并包含您的视图的代码吗?
-
是的,我现在将其弹出...完成。编辑已经取出表格标签。它实际上有点 magled 它,但 foreach 就在那里。
标签: linq-to-sql asp.net-mvc-3 razor