0

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 Answer 1

0

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 ?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.