OK, I've changed the Model so that DomainPages and ContentPages are IEnumerable and when I run in debug mode and check the controller they are getting populated correctly.
I've got @model IEnumerable at the start of my view but I'm still getting an error
The model item passed into the dictionary is of type 'admTest.Models.SitePageViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[admTest.Models.SitePageViewModel]'.
Model
public class SitePageViewModel
{
public IEnumerable<SitePage> DomainPages { get; set; }
public IEnumerable<SitePage> ContentPages { get; set; }
}
Controller
public ViewResult Index()
{
var Model = new SitePageViewModel();
Model.DomainPages = (from d in db.SitePages where d.SiteId == null select d).ToList();
Model.ContentPages = (from c in db.SitePages where c.SiteId != null select c).ToList();
return View(Model);
}
View
@model IEnumerable<admTest.Models.SitePageViewModel>
nielsm59
Member
36 Points
10 Posts
Re: Returning data from a viewmodel to one ActionResult with ASP.NET MVC
Aug 08, 2011 05:30 PM|LINK
OK, I've changed the Model so that DomainPages and ContentPages are IEnumerable and when I run in debug mode and check the controller they are getting populated correctly.
I've got @model IEnumerable at the start of my view but I'm still getting an error
The model item passed into the dictionary is of type 'admTest.Models.SitePageViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[admTest.Models.SitePageViewModel]'.
Model public class SitePageViewModel { public IEnumerable<SitePage> DomainPages { get; set; } public IEnumerable<SitePage> ContentPages { get; set; } } Controller public ViewResult Index() { var Model = new SitePageViewModel(); Model.DomainPages = (from d in db.SitePages where d.SiteId == null select d).ToList(); Model.ContentPages = (from c in db.SitePages where c.SiteId != null select c).ToList(); return View(Model); } View @model IEnumerable<admTest.Models.SitePageViewModel>