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

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

问题描述

如何在 Asp.Net mvc 中使用 Datatable 而不是实体框架?

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....我可以返回数据表而不是电影或电影列表对象吗??

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.

如果您想遍历视图中的 DataTable,请将其放在控制器中的 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.

DataTable 是可序列化的.

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

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天全站免登陆