首页 > Web开发 > 详细

ASP.NET MVC3.0中同一View如何返回多个Model或数据集

时间:2014-02-26 12:03:49      阅读:370      评论:0      收藏:0      [点我收藏+]

在控制器里定义一个Dictionary 泛型类,再把要用到的不同模型加进去

 controller:

    public ActionResult Index() {   


IDictionary<string, object> test = new Dictionary<string, object>();
test.Add("StudentList", new List<StudentInfo>());
return View(test);
}

 view视图:

@model IDictionary<string, object> 
@{Layout = null; }
<!DOCTYPE html>
<html>
<head>
<title>我的个人主页</title>
</head>
<body>
<ul style="list-style: none; margin-left: 10px;">
@foreach (var m in (IList<EnglishDiary.Models.StudentInfo>)Model["StudentList"]) {
<li>@m.StuID</li>
<li>@m.StuName</li>
}
</ul>
</body>
</html>

ASP.NET MVC3.0中同一View如何返回多个Model或数据集

原文:http://www.cnblogs.com/512sz/p/3567590.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!