ASP.Net MVC--Foreach循环遍历ViewBag(存放DataSet数据类型)

控制器代码:

DataSet userlist = db.Query("SELECT ID,UserName FROM [dbo].[User]");
ViewBag.userlist = userlist;

View视图页代码:

@foreach (System.Data.DataRow items in (ViewBag.userlist as System.Data.DataSet).Tables[0].Rows)
                        {

                            if (items["ID"].ToString() == item.applyman.ToString())
                            {
                                @items["UserName"]
                            }

                        }

完美解决!

posted @ 2019-07-30 09:23  初晨~  阅读(3358)  评论(0编辑  收藏  举报