My controller is querying a database. The results are returned in a DataTable. I want to display each DataRow of the DataTable in my view. In my controller, I have the following:
DataTable results = QueryDatabase();
ViewBag.Results = results;
I’m using RAZOR syntax in my ASP.NET MVC view. However, I’m not sure how to iterate through the rows and render each record. What is the recommended approach for doing this kind of task?
First set the viewbag to rows instead of the table, so
ViewBag.Results = results.Rows;Then to iterate through the rows use: