I have the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MyTestWebsite.Models
{
public class Page
{
public int Id { get; set; }
public int AuthorUserId { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Content { get; set; }
public bool Hidden { get; set; }
}
public class PageState
{
public int Id { get; set; }
public string Type { get; set; }
}
public class MyTestWebsiteDBContext : DbContext
{
public DbSet<Page> Pages { get; set; }
public DbSet<PageState> PageStates { get; set; }
}
}
I went to create a controller for Page and I found the model structure.. no problems.
This is, I need another model called PageState and my model list does not show this second model.
Is it usual to have a heck load of models…. regardless of them being linked in some way?
Do I just add a model on its own called PageState?
Yes, they are called view models. Each view should have a specific view model. It’s perfectly normal to have many view models if you have many views. A view model could aggregate one or more of your EF domain models.