Handlebars.Net Iterate over list [HandlebarsUndefinedBindingException]

92 Views Asked by At

I have just started using Handlebars.Net. I have a template containing:

{{#each InvoiceLines}}
   Desc = {{Description}} , Cost = {Cost}}
{{/each}}

My data object is as per below:

public class Data
{
    public bool IsRenewalInvoice { get; set; }
    public List<InvoiceLine> InvoiceLines { get; set; } 
}

public class InvoiceLine
{
    public string Description { get; set; }
    public string Cost { get; set; }
}

However, I am getting a HandlebarsUndefinedBindingException: 'Description is undefined'. I have also tried using this and InvoiceLine before the property name of the list item as below but that also does not work.

Desc = {{this.Description}} , Cost = {this.Cost}}
Desc = {{InvoiceLine.Description}} , Cost = {InvoiceLine.Cost}}

How do I get this to work?

Also, if the list is nested in another object within Data - Is it still possible to access the properties of the list item?

1

There are 1 best solutions below

0
Stef Heyenrath On

There seems to be small error in your template: {Cost}} instead of {{Cost}}.

It should be

{{#each InvoiceLines}}
   Desc = {{Description}} , Cost = {{Cost}}
{{/each}}

Can you try that ?