How do I use Datatable instead of Entity framework in Asp.Net mvc?
I\'m referring to this tutorial on the asp.net Website .... http://www.asp.net/Learn/mvc/tutorial-
If I understand your question correctly, just because you are using MVC you do not have to use Entity framework to communicate with the database.
Inside your controller you can use whatever means you want to get the data out of the database. Then you can either transform that data into a custom object which you pass to your View, or you could potentially just pass a DataTable to your view.
Your view just has to know how to iterate through your object that you pass to it.
However, I recommend using POCO objects to pass to your view, so that you don't tightly couple your view data to the technology used to extract information from the database.
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.
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 is serializable.
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);
}
}
%>