为什么剃刀不是这样? [英] Why does Razor not like this?

查看:138
本文介绍了为什么剃刀不是这样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ive得到了一个大型恼人的问题,我有一个观点:

Ive got a mega annoying problem I have a view with:

@{

        if(ViewBag.Section == "Home")
        {
           <div id="headerfrontPage">   
        }
        else
        {
            <div id="header">   
        }


     }

和我得到一个编译错误:

And I get a compilation error:

在code座缺少结束}字符。请确保您有
  匹配}字符该块内的所有的{字符,
  并且没有的}字符正在PTED为标记间$ P $。

The code 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.

我如何写有条件的div?它一劈bascially ...

How do I conditionally write a div? Its for a hack bascially...

推荐答案

我怀疑那是因为你的div没有关闭,所以剃须刀假定右括号实际上是div内容的一部分。

I suspect it is because your divs are not closed, so razor assumes that the closing brace is actually part of the div content.

您可以尝试你的输出code内的整个内容的div那里,其中包括结束标记,或输出用的Response.Write div标签,或者类似的东西,所以没有混乱的标记。

You might try outputting the entire div content within your code there, including the closing tag, or output the div tag with a Response.Write, or something similar, so there is no confusing markup.

编辑:也可能封闭在您的div标签

also, maybe enclosing your div tag in a

<text></text>

可能是值得一试。

might be worth a try.

这篇关于为什么剃刀不是这样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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