How can I pass datatable to the mvc view
How would I iterate over it in the view
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(); %>
<%}%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With