I'm using MVC (for the first time) with Entity framework, Database first
What I want to do is display data from a database in a single view. I created the database first, then I made a ADO.NET Entity Data Model based from the database that contains all the tables. I then created a Index view that was strongly typed with my Entity Data Model as model.
In my Index I have at the top
@model IEnumerable<Forum6.Models.Forum>
This allows me to get the rows from the table "Forum" from my database. If I try to add an extra model I get I get this error message when I run:
Line 1: @model IEnumerable<Forum6.Models.Forum> Line 2: @model2 IEnumerable<Forum6.Models.Post>Parser Error Message: Only one 'model' statement is allowed in a file.
After searching for an answer I found this: Two models in one view in ASP MVC 3 The answer was to create a ViewModel (ParentModel) that contained all the Models (Tables). This is the ViewModel I created:
public class ViewModel
{
    public IEnumerable<Forum6.Models.Forum>         Forum       { get; set; }
    public IEnumerable<Forum6.Models.Post>          Post        { get; set; }
    public IEnumerable<Forum6.Models.Topics>        Topics      { get; set; }
    public IEnumerable<Forum6.Models.Users>         Users       { get; set; }
    public IEnumerable<Forum6.Models.PrivMsg>       PrivMsg     { get; set; }
    public IEnumerable<Forum6.Models.Permission>    Permission  { get; set; }
}
I edited my controller to look like this:
   public class HomeController : Controller
{
    // ForumDBEntities old_db = new ForumDBEntities();
    ViewModel db = new ViewModel();
    public ActionResult Index()
    {
        return View(db);
    }
}
Then replaced the old Index view with a new strongly typed view that used the ViewModel as model. Which contains:
@model IEnumerable<Forum6.Models.ViewModel>
Trying to run this gives me this error:
The model item passed into the dictionary is of type 'Forum6.Models.ViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Forum6.Models.ViewModel]
How do I make the "ViewModel" enumarable? Or is my error elsewhere?
 
     
    
 
    