Razor doesn't understand unclosed html tags

前端 未结 4 922
灰色年华
灰色年华 2020-12-04 17:11

With RazorViewEngine, I can do this:

if (somecondition) {
     
some stuff
}

but I can\'t seem to do this (Razor ge

4条回答
  •  攒了一身酷
    2020-12-04 18:02

    The fact that you have to do this usually indicates that your view code is not factored correctly. The nature of HTML is to have balanced or self-enclosed tags (at least in HTML 4, HTML 5 seems to be leaning away from it) and Razor depends on that assumption. If your going to conditionally ouptut a

    then you will also somewhere later output
    . Just put the whoel pair in your if statement:

    @if(something) {
        
    Other stuff
    }

    Otherwise you end up with weird code like here.

提交回复
热议问题