zoukankan      html  css  js  c++  java
  • ASP.NET MVC3.0中同一View如何返回多个Model或数据集

    在控制器里定义一个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>
  • 相关阅读:
    正向代理和反向代理
    Unicode
    utf-8
    ISO 8895-1
    ProtocalBuffers学习记录
    C#基础知识
    MSBuild学习记录
    Linux学习笔记
    Jenkins学习记录
    CruiseControl.Net学习记录
  • 原文地址:https://www.cnblogs.com/512sz/p/3567590.html
Copyright © 2011-2022 走看看