MVC3中任何把DataTable的数据在view上显示
Controllers中
public ActionResult Index()
{
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["connstr"].ToString());
conn.Open();
DataTable datatable = new DataTable();
OleDbCommand comm = new OleDbCommand("select * from UserList",conn);
OleDbDataAdapter dar = new OleDbDataAdapter(comm);
dar.Fill(datatable);
conn.Close();
conn.Dispose();
Model.UserList userlist = new UserList();
List<Model.UserList> list_m = new List<UserList>();
list_m =(List<Model.UserList>)Model.ModelConvertHelper<Model.UserList>.ConvertToModel(datatable);
return View(list_m); //list_m是list<model>的数据
}view中要怎么显示list_m的值
@model IEnumerable<MVC.Model.UserList> //这个一直认不到
@{
foreach (var item in Model)
{
Response.Write(item); //这里一直读不到值,
}
}
------解决方案--------------------Refer this:
http://www.cnblogs.com/insus/p/3361182.html
------解决方案--------------------把datatable转换成list吧。。