Model:
public class NewsCenter
{ //新闻的所有字段
[Key]
public int news_id { get; set; }
public string news_title { set; get; }
public int news_typeid { get; set; }
public string news_content { get; set; }
public string news_editor { get; set; }
public DateTime news_date { get; set; }
public NewsType news_type { get; set; }
}
public class NewsType
{//新闻的分类
[Key]
public int news_typeid { get; set; }
public string news_type { get; set; }
public List<NewsCenter> NewsCenter { get; set; }
}
public class NewsCenterDB : DbContext
{
public DbSet<NewsCenter> News { get;set; }
public DbSet<NewsType> NewsType { get; set; }
}
请问View中怎么显示出Newscenter的所有字段,求Action
public class NewsCenter
{ //新闻的所有字段
[Key]
public int news_id { get; set; }
public string news_title { set; get; }
public int news_typeid { get; set; }
public string news_content { get; set; }
public string news_editor { get; set; }
public DateTime news_date { get; set; }
public NewsType news_type { get; set; }
}
public class NewsType
{//新闻的分类
[Key]
public int news_typeid { get; set; }
public string news_type { get; set; }
public List<NewsCenter> NewsCenter { get; set; }
}
public class NewsCenterDB : DbContext
{
public DbSet<NewsCenter> News { get;set; }
public DbSet<NewsType> NewsType { get; set; }
}
请问View中怎么显示出Newscenter的所有字段,求Action
public NewsType()
{
//建议改为NewsListWithType
NewsCenter = db.News.Where(n=>n.news_typeid=news_typeid).ToList();
}
或者你也可以用初始化器整进去 news_type = new NewsType(){...}类的设计上有点小冗余 news_typeid 和 news_type.news_typeid
http://topic.csdn.net/u/20110414/10/06526263-9e0d-491f-b963-7ae0afd1f7e4.html