MVC3.0 Razor 单个View页返回多个model实体数据集

namespace Models
{
    public class Articel
    {
        public int Id { get; set; }
        [Required]
        [DisplayName("标题")]
        [MaxLength(100)]
        public string Title { get; set; }
    }
 
    public class Cate
    {
        public int CateId { get; set; }
        [DisplayName("文章类别")]
        [Required]
        public string CateName { get; set; }
 
        public List
article { get; set; } } public class ListModel { /// /// 文章 /// public IList
artcleModel { get; set; } /// /// 文章类别 /// public IList cateModel { get; set; } } }
 
  
Action方法编写如下:

public  ActionResult Index()
         {
             var  model =  new  ListModel();
             model.artcleModel= Articel.ToList();
             model.cateModel= Cate.ToList();
             return  View(model);
         }
 
View层引用如下:
@model Models.ListModel
 
@ foreach  ( var  tt  in  Models.artcleModel)
             {
              @tt.Title
             }
 
@ foreach  ( var  tt  in  Models.cateModel)
             {
               @tt.CateName
             }

你可能感兴趣的:(MVC3.0 Razor 单个View页返回多个model实体数据集)