C# Template Engine which supports iterating through data rows in DataTable

525 Views Asked by At

I'm looking for a C# template engine which supports iterating through data rows in DataTable. Something like,

var template = Template.Parse(@"
    <ul id='products'>
      {{ for dr in ds.tables[0].rows }}
         <li>
           <h2>{{ dr[0] }}</h2>
           Price: {{ dr[1] }}
         </li>
      {{ end }}
    </ul>
");

var result = template.Render(new { Ds = ds});

I tried Scriban, but it throws error

Scriban.Syntax.ScriptRuntimeException: '<input>(3,31) : error : Expecting a list. 
Invalid value `System.Data.DataTableCollection/DataTableCollection` for the target `ds.tables` for the indexer: ds.tables[0]'

Is there a way to make it work in Scriban, or is there any other template engine which supports DataSet

0

There are 0 best solutions below