Razor doesn’t understand unclosed html tags

asp.net-mvc-3razor

With RazorViewEngine, I can do this:

if (somecondition) {
     <div> some stuff </div>
}

but I can't seem to do this (Razor gets confused):

if (somecondition) {
    <div>
}

if (someothercondition) {
    </div>
}

I have a situation in which I need to put my opening and closing html tags in different code blocks – how can I do this in Razor?

Best Answer

Try like this:

if (somecondition) {
    @:<div>
}