C#模板引擎,支持对DataTable中的数据行进行迭代

时间:2019-04-04 15:33:23

标签: c# razorengine stringtemplate dotliquid scriban

我正在寻找一个C#模板引擎,该引擎支持对DataTable中的数据行进行迭代。像

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});

我尝试过Scriban,但会引发错误

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]'

是否有办法使其在Scriban中工作,或者是否有其他任何支持DataSet的模板引擎

0 个答案:

没有答案