How to add row with multiple columns and it should have two normal column and one dropdown column on ajax success

Monisha S 21 Reputation points
2021-09-25T18:34:10.19+00:00

Html code:
@默 Sampleapplication.Models.samplemodel

<body>
<table id="tabledetails" class="table table-bordered loaded-table">
<thead>
<tr>

                    <th>  <p>Id</p></th>  
                    <th>  <p>Name</p></th>  
                    <th>  <p>Department</p></th>  
                   
                </tr>  
            </thead>  
            <tbody></tbody>  
        </table>  

</body>

success: function (data) {

                     $.each(data, function (i, item) {  

                         var rows = "<tr>"  


                             + "<td class='prtoducttd1'>" + item.Id + "</td>"  
                             + "<td class='prtoducttd2'>" + item.Name + "</td>"  
                             
                             + "<td class='prtoducttd11'>@Html.ListBoxFor(m => m.sDepartmentList, Model.lstToDepartment, new { Name = "Departmentlst", id = "Departmentlst", @placeholder = "Select Deaprtment" })</td>"  
                             + "</tr>";  
                         $('#tabledetails tbody').append(rows);  

});

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,243 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 54,866 Reputation points
    2021-09-28T15:31:51.47+00:00

    you need to add the drop down list list values to the data (an array of values). assume the value list is items.Values [{Id,Name}] then its:

    $("<tr/>").append(
        $("<td/>").append(
             $("<select/>").append(
                    item.Values.map(v => $("<options/>").val(v.Id).text(v.Name)}
             )
         )
    )
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful