Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc datatable

How can I pass datatable to the mvc view

How would I iterate over it in the view

like image 247
maztt Avatar asked Jan 22 '23 02:01

maztt


1 Answers

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

 <%}%>
like image 175
Silas Hansen Avatar answered Jan 26 '23 11:01

Silas Hansen