数据表,而不是Asp.Net MVC实体框架 [英] DataTable instead of Entity framework in Asp.Net MVC

查看:93
本文介绍了数据表,而不是Asp.Net MVC实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用,而不是Asp.Net MVC?

How do I use Datatable instead of Entity framework in Asp.Net mvc?

我指的是本教程在asp.net网站....
http://www.asp.net/Learn/mvc/tutorial-21 -cs.aspx
....我可以返回一个数据表,而不是电影或movielist对象??

I'm referring to this tutorial on the asp.net Website .... http://www.asp.net/Learn/mvc/tutorial-21-cs.aspx ....Can I return a datatable instead of a movie or movielist object??

推荐答案

您可以返回任何你想要的ViewData的,只要它可以存储(连载)。没有什么魔力关于ASP.NET MVC的限制值和/或类型。

You can return whatever you want provided it can be stored (serialized) in the ViewData. There is nothing "magic" about ASP.NET MVC that constrains values and/or types.

如果你想遍历在视图中数据表,把它放在ViewData的控制器,在视图检索它,并且迭代它,你会在其他地方。

If you want to iterate over the DataTable in the view, put it in ViewData in the controller, retrieve it in the View, and iterate over it as you would anywhere else.

数据表是可序列化

所以类似下面的东西应该工作:

So something similar to the following should work:

<%
var tbl = ViewData["MyDataTable"];

foreach (DataRow row in tbl.Rows)
{
  foreach (DataColumn col in tbl.Columns)
  {
    Response.Write(row[col] as string ?? string.Empty);
  }
}
%>

这篇关于数据表,而不是Asp.Net MVC实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆