tags:

views:

59

answers:

2

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.

A: 

Here's just two options you could.

  1. 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;
        }
    }
    
  2. 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.

David Liddle
1. DataTable is NOT serializable. 2. You do not return to your view anything but pass to it. 3. Object in order to be passed to view does not need to be serializable.
Arnis L.
Sorry I was meant to put NOT serializable therefore you create a strongly typed object from your DataTable hence my example.
David Liddle
+1  A: 

Read this MVC introduction by ScottGu. You should use the solution titled "Implementing our ViewPage implementation using <%= %> Code".

PanJanek