views:

209

answers:

1

How can I pass datatable to the mvc view

How would I iterate over it in the view

+2  A: 

In your controller:

public ActionResult Index()
{
    DataTable dt = new DataTable();
    return View(dt);
}

In your View: Just make your model of type DataTable

Inherits="System.Web.Mvc.ViewPage<System.Data.DataTable>"

To iterate over it:

 <% foreach (System.Data.DataRow row in Model.Rows) { %>

        <%= row["column"].ToString(); %>   

 <%}%>
Silas Hansen
Ok thanks but I want to add in my question how would i iterate over it
mazhar kaunain baig