I want to pass two collections of objects. First is Post
, second is Gallery
. However I get error and I don't know how to fix this.
I've done this when passing two single objects and it is working fine, but now I need to pass two collections of those objects and it gives me error.
Error
The model item passed into the dictionary is of type 'System.Tuple
2[System.Linq.IQueryable
1[photoBlog.Models.Gallery],System.Linq.IQueryable1[photoBlog.Models.Post]]', but this dictionary requires a model item of type 'System.Tuple
2[System.Collections.Generic.IEnumerable1[photoBlog.Models.Gallery],System.Collections.Generic.IEnumerable
1[photoBlog.Models.Post]]'.
Controller
public ActionResult Index()
{
photoBlogModelDataContext _db = new photoBlogModelDataContext();
var posts = _db.Posts.OrderByDescending(x => x.DateTime).Take(4);
var galleries = _db.Galleries.OrderByDescending(x => x.ID).Take(4);
return View(Tuple.Create(galleries, posts));
}
View
@model Tuple<IEnumerable<photoBlog.Models.Gallery>, IEnumerable<photoBlog.Models.Post>>
@foreach (var item in Model.Item1)
{
@item.Name
}