我收到这个错误。
传入字典的模型项的类型为“System.Data.Entity.Infrastructure.DbQuery 1[<>f__AnonymousType1
3[ACapture.Models.Blog,ACapture.Models.Image,ACapture.Models.Profile]]”,但此字典需要模型项'System.Collections.Generic.IEnumerable`1[ACapture.Models.Blog]' 类型。
这是我的控制器。
public class HomeController : Controller
{
private ACaptureDB db = new ACaptureDB();
public ViewResult Index()
{
ViewBag.Message = "ArchiCapture";
var dateCheck = DateTime.Now.AddDays(-7);
var results = (from r in db.Blog
join p in db.Image on r.ImageID equals p.ImageID
//join l in db.Account on p.AccountID equals l.AccountID
join a in db.Profile on p.AccountID equals a.AccountID
//where r.dte_created >= dateCheck
select new { r, p, a });
return View(results);
}
这是我的看法。
@model IEnumerable<ACapture.Models.Blog>
@{
ViewBag.Title = "Home Page";
}
<div class="Forum">
<p>The Forum</p>
@foreach (var item in Model)
{
<div class="ForumChild">
<img src="@item.Image.img_path" alt="Not Found" />
<br />
<table>
@foreach (var comment in item.comment)
{
var db = new ACapture.Models.ACaptureDB();
var Name = from p in db.Profile
where (p.AccountID == comment.AccountID)
select new { p.FirstName, p.LastName };
<tr><td></td><td>@comment.Commentation</td></tr>
}
</table>
</div>
}
</div>
每当数据从控制器传递到视图时,就会发生错误。
我还需要来自所有三个表博客、图像和个人资料的数据