Developer technologies | ASP.NET | Other
A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
how to display list of dynamic tables from controller on view in asp.net?
Hi @Muhammad Faheem ,
Do you want to return the list data from the controller and display it in the table?
You can refer to the following demo.
Model:
public class Test
{
public int Id { get; set; }
public string Name{get; set; }
public int Age { get; set; }
}
Controller:
public ActionResult Test()
{
List<Test> result = new List<Test>
{
new Test{Id=1,Name="Test01",Age=12},
new Test{Id=2,Name="Test02",Age=13},
new Test{Id=3,Name="Test03",Age=14},
};
return View(result);
}
View:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>@item.Id</td>
<td>@item.Name</td>
<td>@item.Age</td>
</tr>
}
</tbody>
</table>
Result:
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
ChaoDeng