我的C#code的结束括号在剃刀局部视图无法识别 [英] The closing braces of my C# code are not recognized in a Razor partial view

查看:300
本文介绍了我的C#code的结束括号在剃刀局部视图无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个asp.net MVC 3应用程序。我用剃刀我的看法。我有这个问题周五,以为我有固定的,但现在我看到,这只是其中的事情工作因为某些原因一些私人情况。

I am working on a asp.net mvc 3 application. I use Razor for my views. I had this problem friday and thought I have fixed it but now I see that it was just some private case where the things worked for some reason.

我有四列的表,但每一行可能有不同数量的字段在一个单元格,所以我工作的一些排序算法这将填补我的细胞属于他们所有的信息。这就是我现在:

I have a table with four columns, but each row may have different number of fields in one cell so I'm working on some sort of algorithm which will fill my cells with all the info that belong to them. This is what I have now :

@{
    int tempColumn = 1;    
}

<tr>
@foreach (var field in Model)
{   
    if (field != null)
    {   
        <td>    
        @for (int i = 0; i < field.Count; i++)
        {
            if (field[i].ColumnNo == tempColumn)
            {
                @field[i].QuestionText;
                @field[i].FieldValue;
            }
            else if (field[i] != null)
            {
                tempColumn++;
                @:</td>
                @:<td>
                @field[i].QuestionText;
                @field[i].FieldValue;
            }
        }
    }
    @:</td>      
}
</tr>

基本上这个想法是,不管有多少对 @field [I] .QuestionText的; / @field [I] .FieldValue; 我有我将永远有一个开口&LT; TD&GT; 在该行的开头标记和结束&LT; / TD&gt;对于该行的末尾标记。我有一个算法问题太多,但我之前解决该问题与不承认收手镯我无法继续。那么,什么是错误 - 当我尝试调试模式运行这个code我得到这个错误:

Basically the idea is that no matter how many pairs of @field[i].QuestionText; / @field[i].FieldValue; I have I will always have an opening <td> tag at the begining of the row and closing </td> tag at the end of the row. I have problems with the algorithm too but before I fix the issue with the not recognized closing bracelets I can't continue. So what is the error - when I try and run this code in debug mode I get this error :

在foreach块缺少结束}字符。确保你
  有在这一切的{字符匹配的}字符
  块,而没有}字符正在跨$ P $的作为PTED
  标记。

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

但是,当我去到code本身我得到有关如果块同样的错误了阻塞。我以为插入HTML &LT; TD&GT; &LT; / TD&GT; 使用此语法标记 - @ 将让我的C#code的sructure,只是补充,我想他们的标签,但我觉得似乎有些道理至少有一个&LT; TD&GT; &LT; / TD&GT; 标记间preTED让一切都被识别为HTML标记后不是C#code。那么,什么是插入HTML标记在C#方法的正确方法,或者如果错误是从别的原因 - 什么?难道是

But when I go to the code itself I get the same error about the if block and the for block. I thought that inserting the HTML <td> and </td> tags using this syntax - @: will keep the sructure of my C# code and just add the tags where I want them, but from what I think it seems that some reason at least one <td> or </td> tag is interpreted so that everything after it is recognized as HTML markup and not C# code. So what is the proper way to insert HTML markup in a C# method, or if the error is cause from something else - what could it be?

P.S

有关算法任何帮助将是AP preciated虽然它不是这个问题的话题。

Any help about the algorithm would be appreciated though it's not the topic of this question.

推荐答案

修改

            }
        }
    }
    @:</td>      
}
</tr>

            }
        }
        </td>      
    }
}
</tr>

您启动&LT; TD&GT; 中的如果(场!= NULL)所以你应该结束里面有作为,否则,如果字段== NULL 你会得到&LT; TR&GT;&LT; / TD&GT;&LT; / TR&GT;

You start your <td> inside the if (field != null) so you should end in inside there as well, otherwise if field == null you'll get <tr></td></tr>.

这篇关于我的C#code的结束括号在剃刀局部视图无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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