maztt
maztt

Reputation: 12304

asp.net mvc datatable

How can I pass datatable to the mvc view

How would I iterate over it in the view

Upvotes: 4

Views: 7422

Answers (1)

Silas Hansen
Silas Hansen

Reputation: 1739

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(); %>   

 <%}%>

Upvotes: 9

Related Questions