ASP.NET

单个View页返回多个model实体数据集

时间:2014-10-25 16:59:51  作者:WPF之家  来源:http://www.wpf123.com/  查看:1158  评论:0
内容摘要:namespace Models{ public class Articel { public int Id { get; set; } [Required] [DisplayName("标题")] ...
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> article { get; set; }
    }
 
    public class ListModel
    {
        /// <summary>
        /// 文章
        /// </summary>
        public IList<Article> artcleModel { get; set; }
 
        /// <summary>
        /// 文章类别
        /// </summary>
        public IList<Cate> 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
            }

标签:asp.net mvc 多个  model 

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。本文出自“wpf之家”,请务必保留此出处:http://www.wpf123.com

相关评论
Copyright © 2009-2014 WPF之家(http://www.wpf123.com/) All rights reserved
 Powered by WPF之家
鄂ICP备13006396号