MVC3剃刀有条件的包装DIV [英] mvc3 razor conditional wrapper div

查看:117
本文介绍了MVC3剃刀有条件的包装DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是处理这样的事情最好的办法:

剃须刀code:

  @if(!disableRowDiv)
{
    < D​​IV CLASS =行>
}< D​​IV>此处的某些内容和LT; / DIV>@if(!disableRowDiv)
{
    < / DIV>
}

这样的剃刀引擎不会产生这个错误:

分析器错误信息:


  

if块缺少结束}字符。确保你有一个匹配的}字符此块内的所有的{字符,并且没有任何的}字符正在PTED为标记间$ P $。



解决方案

这应该工作

  @if(!disableRowDiv)
{
    @:其中,DIV CLASS =行>
}
< D​​IV>此处的某些内容和LT; / DIV>
@if(!disableRowDiv)
{
    @:LT; / DIV>
}

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.

解决方案

This should work

@if(!disableRowDiv)
{
    @:<div class="row">
}
<div>some content here</div>
@if(!disableRowDiv)
{
    @:</div>
}

这篇关于MVC3剃刀有条件的包装DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆