mvc3 razor conditional wrapper div

2019-03-11 15:06发布

What's the best way to handle something like this:

Razor Code:

@if(!disableRowDiv)
{
    <div class="row">
}

<div>some content here</div>

@if(!disableRowDiv)
{
    </div>
}

So that the Razor engine doesn't produce this error :

Parser Error Message:

The if block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-03-11 16:08

This should work

@if(!disableRowDiv)
{
    @:<div class="row">
}
<div>some content here</div>
@if(!disableRowDiv)
{
    @:</div>
}
查看更多
登录 后发表回答