I have to generate table dynamically in html using c# list
I generated HTML with dynamic data but need dynamic table in between. I was able to add dynamic data but not able to add dynamic table please help me with same.
-
- var template = (await _packItemsDataService.GetLayoutData(collectionSite))?.Payload;
-
- var templateData = await PopulateLetterTemplateWithDataForApplication(dispatchDetail);
-
- private async Task<Dictionary<string, object>> PopulateLetterTemplateWithDataForApplication(DispatchDetailResponse dispatchDetail)
- {
- return new Dictionary<string, object>()
- {
- {"siteFrom", dispatchDetail.DispatchDetail.FromSiteId},
- {"siteShippedTo", dispatchDetail.DispatchDetail.ToSiteId},
- {"dispatchDate", dispatchDetail.DispatchDetail.UpdatedOn},
- {"numberOfContainers", dispatchDetail.DispatchDetail.ContainerDetails.Count},
- {"OperatorName", dispatchDetail.DispatchDetail.Name},
- {"courierName", dispatchDetail.DispatchDetail.CourierName},
- {"containerDetails", dispatchDetail.DispatchDetail.ContainerDetails}
- };
- }
-
- var document = _templateGenerator.Generate(template, templateData);
- public string Generate(string sourceTemplate, IDictionary<string, object> templateData){
- var template = HandlebarsDotNet.Handlebars.Compile(sourceTemplate);
- var builtFile = template(templateData);
- return builtFile;
- }
-
- public class DispatchDetailResponse
- {
- public DispatchDetail DispatchDetail { get; set; }
- public string Reason { get; set; }
- }
- public class DispatchDetail : Dispatch
- {
- public List<ContainerDetail> ContainerDetails { get; set; }
- public int DispatchLocationId { get; set; }
- }
-
- public class ContainerDetail : Container
- {
- public List<DispatchInfoStockItem> DispatchInfoStockItems { get; set;
- }
- }
- public class DispatchInfoStockItem
- {
- public string DocumentType { get; set; }
- public string DocumentNumber { get; set; }
- public string ApplicantFirstName { get; set; }
- public string ApplicantLastName { get; set; }
- public StockItem StockItem { get; set; }
- }
//HTML CODE
- <!DOCTYPE html>
- <html lang="en">
- <div class="col-md-3 col-sm-6 form-group"> </div>
- <div class="col-md-3 col-sm-6 form-group"> </div>
- <div class="col-md-3 col-sm-6 form-group"> </div>
- <div class="col-md-3 col-sm-6 form-group"><label id="lblCardBodyNumber"
- class="control-label" for="cardBodyNumber">Site
- From</label> : {{siteFrom}}
-
- Site Shipped To: {{siteShippedTo}}</div>
- <div class="col-md-3 col-sm-6 form-group"> </div>
- <div class="col-md-3 col-sm-6 form-group">Number of containers:
- {{numberOfContainers}} Dispatch Date: {{dispatchDate}}</div>
- <div class="col-md-3 col-sm-6 form-group"> </div>
- <div class="col-md-3 col-sm-6 form-group"> </div>
- <div class="col-md-3 col-sm-6 form-group">
- <table style="height: 139px; border-color: black; width: 900px;"
- border="2">
- <tbody>
- <tr style="height: 15px;">
- <td style="width: 139px; height: 15px;">Continer Number</td>
- <td style="width: 119px; height: 15px;">Document Type</td>
- <td style="width: 143px; height: 15px;">Document Number</td>
- <td style="width: 105px; height: 15px;">Applicant First Name</td>
- <td style="width: 139px; height: 15px;">Applicant Last Name</td>
- </tr>
- <tr style="height: 66px;">
- <td style="width: 139px; height: 66px;"> </td>
- <td style="width: 119px; height: 66px;"> {{documentType}}</td>
- <td style="width: 143px; height: 66px;"> {{documentNumber}}</td>
- <td style="width: 105px; height: 66px;"> {{ApplicantFirstName}}</td>
- <td style="width: 139px; height: 66px;"> {{ApplicantLastName}}</td>
- </tr>
- </tbody>
- </table>
- </div>
- <div class="col-md-3 col-sm-6 form-group"> </div>
- <div class="col-md-3 col-sm-6 form-group"> Sending Operator:
- {{OperatorName}}
- Courier Name<label id="lblLocation" class="control-label"
- for="locations">: {{courierName}} </label></div>
- <div class="col-md-3 col-sm-6 form-group"> </div>
- <div class="col-md-3 col-sm-6 form-group"><label id="lblStockNumber"
- class="control-label" for="stockNumber"> Operator Sign:
-
-
- Courier Sign:
- </label> </div>
- <div class="row">
- <div class="col-md-3 form-group"> </div>
- </div>
- </html>
Expected:
Dynamic data in html table using DispatchInfoStockItem list from ContainerDetail class.
please check html code in browser to get reference of the table which I want