执行效果:
3.2、集合字典遍历
控制器:
/// <summary> /// 默认字典 /// </summary> /// <returns></returns> public Dictionary<string, Object> DefaultMap() { Dictionary<string, Object> map = new Dictionary<string, object>(); map.Add("code",200); map.Add("message","访问成功"); map.Add("result",DefaultList()); return map; }
//传递值视图 ViewBag.list = DefaultMap();
视图:
返回编码:@ViewBag.list["code"] <hr/> 返回消息:@ViewBag.list["message"] <table class="table table-bordered table-hover table-striped"> <tr class="info"> <td>编号</td> <td>创建时间</td> <td>昵称</td> <td>年龄</td> <td>简介</td> </tr> @foreach (var item in ViewBag.list["result"]) { <tr> <td>@item.id</td> <td>@item.createDate</td> <td>@item.nickName</td> <td>@item.age</td> <td><pre>@item.introduce</pre></td> </tr> } </table>
第二章【二、数据传递】完结。
【一、控制器与视图:https://laoshifu.blog.csdn.net/article/details/120126288】
【二、数据传递:https://laoshifu.blog.csdn.net/article/details/120127320】
【三、表单与文件上传:https://laoshifu.blog.csdn.net/article/details/120130566】
【四、ASP.NET Web API应用程序与跨域操作:https://laoshifu.blog.csdn.net/article/details/120160728】
【五、HttpClient接口解析:https://laoshifu.blog.csdn.net/article/details/120332379】