how to display list of dynamic tables from controller on view in asp.net?
how to display list of dynamic tables from controller on view in asp.net?
Hi @MuhammadFaheem-4747,
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
9 people are following this question.