I'm sorry, for I'm sure there's a way to do this with a viewModel, however I'm very inexperienced with this and don't even know if I'm doing it correctly.
What I'm trying to do is pass multiple blogs and the profile info of the user who posted each blog to a view.
I'm getting the following error.
The model item passed into the dictionary is of type 'ACapture.Models.ViewModels.BlogViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[ACapture.Models.ViewModels.BlogViewModel]'.
I'm trying to pass the following query results to the view.
var results = (from r in db.Blog.AsEnumerable()
join a in db.Profile on r.AccountID equals a.AccountID
select new { r, a });
return View(new BlogViewModel(results.ToList()));
}
This is my viewModel
public class BlogViewModel
{
private object p;
public BlogViewModel(object p)
{
this.p = p;
}
}
And my view
@model IEnumerable<ACapture.Models.ViewModels.BlogViewModel>
@{
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)
{
<tr><td></td><td>@comment.Commentation</td></tr>
}
</table>
</div>
}
</div>
Thanks in advance.