私はこのエラーを取得しています: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
ねえ、今すぐポップアップします...完了しました。エディタはテーブルタグを取り出しました。それは実際には少し磨かれていますが、foreachがそこにあります。 – Dan