Hi,
I am new to ASP.Net MVC (I m using Ver 1.0), I wanted to display contents of a DataTable on my view. Wat is the easiest way to get it done?
Please help.
Hi,
I am new to ASP.Net MVC (I m using Ver 1.0), I wanted to display contents of a DataTable on my view. Wat is the easiest way to get it done?
Please help.
Here's just two options you could.
Iterate over your DataTable and create a more strongly-typed object.
MyObject o = ...;
foreach (DataRow row in tbl.Rows)
{
foreach (DataColumn col in tbl.Columns)
{
//fill in o row[col] as string ?? string.Empty;
}
}
Have a look at JQGrid http://arahuman.blogspot.com/2009/06/jqgrid-using-mvc-json-and-datatable.html. I'm sure you can take the example and adapt it to your needs.
Read this MVC introduction by ScottGu. You should use the solution titled "Implementing our ViewPage implementation using <%= %> Code".