Razor View Engine: Complex looping and HTML

前端 未结 4 427
夕颜
夕颜 2020-12-28 15:32

I have lots of complex HTML reports in my current project where there we perform lots of conditional rendering of TRs and TDs with rowspans and colspans.

It could so

4条回答
  •  余生分开走
    2020-12-28 15:48

    Razor depends on matching tags to determine the automatic transitions between code and markup. You cannot "disable" this feature of Razor (at least not without rewriting large parts of the Razor parser).

    You can work around it by using Darin's suggestion, though I don't understand (at least not from your simplified example) why your view needs to be so convoluted. Why not write the following code instead:

    @foreach (var ourItem in ourList) {
       
       ...
       
    }
    

    While tags might balance out in the generated markup, the source that you provided makes it very difficult to reason about its correctness.

提交回复
热议问题