question

MuhammadFaheem-4747 avatar image
0 Votes"
MuhammadFaheem-4747 asked DuaneArnold-0443 commented

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?

dotnet-csharpdotnet-aspnet-mvc
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What do you mean by dynamic tables?

0 Votes 0 ·

1 Answer

ChaoDeng-MSFT avatar image
0 Votes"
ChaoDeng-MSFT answered

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:
83okD.png



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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.