Does rajor machine razormachine Support for loop , is there any example in that Following didnt work
md.Title = "Title";
md.TableDt.Add(new TableData { Name = "name1" });
md.TableDt.Add(new TableData { Name = "name2" });
RazorMachine rm = new RazorMachine();
ITemplate template = rm.ExecuteContent(
@"Razor says:@@ok Hello @Model.FirstName @Model.LastName
@foreach (var v in Model.TableDt)
{
v.Name
}
",
new { FirstName = "John", LastName = "Smith" });
Console.WriteLine(template.Result);
Most likely you want the name of the variable v
to be printed.
If so, you are forgetting that you would need to prepend an @
symbol.
The correct code would be:
md.Title = "Title";
md.TableDt.Add(new TableData { Name = "name1" });
md.TableDt.Add(new TableData { Name = "name2" });
RazorMachine rm = new RazorMachine();
ITemplate template = rm.ExecuteContent(
@"Razor says:@@ok Hello @Model.FirstName @Model.LastName
@foreach (var v in Model.TableDt)
{
@v.Name
}
",
new { FirstName = "John", LastName = "Smith" });
Console.WriteLine(template.Result);