ASP.Net MVC - Foreach loops through the ViewBag (DataSet stored data type)

Controller code:

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

View View page code:

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

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

                        }

The perfect solution!

Guess you like

Origin www.cnblogs.com/dcy521/p/11267995.html
Recommended