0

此代码有效:

@{  
    if (...)
    {
        foreach (...)
        {
            if (...)
            {
                if (...)
                {                          
                    if (...)
                    {
                        (*some html*)
                    }                                                     
                }
                else
                {
                    (*some html*)
                }
            }
            else
            {
                (*some html*)        
            }
        }
    }
}

但是,当我添加一个 if/else 语句来得到这个时:

@{  
    if (...)
    {
        foreach (...)
        {
            if (...)
            {
                if (...)
                {   
                    ***ADDING THIS***
                    if (...)
                    {
                        (*opening html tag (no closing tag)*)
                    }
                    else
                    {
                        (*opening html tag (no closing tag)*)
                    }
                    ******************

                    if (...)
                    {
                        (*some html*)
                    }                                                     
                }
                else
                {
                    (*some html*)
                }
            }
            else
            {
                (*some html*)        
            }
        }
    }
}

断了,为什么?现在,在 if/else 之后的 if 语句无法被 Visual Studio 中的语法高亮识别,并且我收到关于缺少 '}' 的错误

4

1 回答 1

0

我添加的标记是一个没有结束标签的开始标签,Razor 不允许这样做。在这种情况下,您可以像这样在代码块中输出 HTML:

@Html.Raw("<html>")

(来自 MS 的 Html.Raw 参考 - http://msdn.microsoft.com/en-us/library/gg568896(v=vs.111).aspx

或这个:

@:<html>

@: 在 Razor 中将某些内容呈现为纯文本

于 2013-10-16T02:27:06.263 回答