Can't seem to conditionally create a new table row using Razor's foreach and if statements?

后端 未结 3 785
日久生厌
日久生厌 2021-01-11 11:28

I want a loop to dynamically create a table up to 2 columns wide, and then increase the number of rows until there are no entries left in the list. Sounds easy, and I came

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-11 11:43

    Razor expects the HTML code following your C# code to be enclosed in a pair of html tags. Here you've got the ending tag first, and the starting tag later, that's why razor had trouble parsing the text.

    Enclosing your html code block in solves this issue as pointed out by Darin.

    You could read this quick guide by Phil Haacked http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx

提交回复
热议问题