4

How can I pass datatable to the mvc view

How would I iterate over it in the view

1 Answer 1

9

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(); %> <%}%> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.