简体   繁体   English

剃刀将我的if语句输出为HTML

[英]Razor outputting my if statement as HTML

So I have a razor which I'm using to check the months and years that a learning module is running for: 因此,我有一把剃须刀,用于检查学习模块运行的月份和年份:

        @{  
                string liClass = "prl-4 prs-3";

                if(cssCount == 4){
                    liClass = "alpha prl-4 prs-3";
                }

                <li class="@liClass">
                <i class="icon-test"></i> 

                if(cYears.Count() > 1) {
                      if (cMonthDisplays.Count() > 1) {

                      @cMonthDisplays[0]<text>&nbsp;</text>@cYears[0] <text>/</text> @cMonthDisplays[1]<text>&nbsp;</text>@cYears[1]
                      } else {
                        @cMonthDisplay<text>&nbsp;</text>@cYears[0] <text>/</text> @cMonthDisplay<text>&nbsp;</text>@cYears[1]
                      }
                }
                else {
                      @cMonthDisplay<text>&nbsp;</text>@cYearDisplay
                }

                </li>
                cssCount++;
            }

The first part of my razor works correctly and the class of the li is replaced when the if statement finds that the count does match 4. 我的剃须刀的第一部分正常工作,并且当if语句发现计数确实匹配4时,将替换li的类。

However after the initial 'if' statement worked the second if statement outputs to my page as HTML. 但是,在初始的“ if”语句工作之后,第二条if语句以HTML输出到我的页面。

This is then displayed on my page: 然后显示在我的页面上:

      if(cYears.Count() > 1) {
            if (cMonthDisplays.Count() > 1) {
               March 2016 / September  2017 
             } 
             else { March, September 2016 / March, September  2017 } 
      } 
      else { March, September 2016, 2017 }

I'm a bit stuck as to why my if statements are displaying only for the second if statement. 对于为什么我的if语句仅显示第二条if语句,我有些困惑。 I'm probably missing something really obvious - but any help would be greatly appreciated! 我可能会错过一些确实很明显的东西-但是任何帮助将不胜感激!

您应该在if之前添加一个@

@if(cYears.Count() > 1) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM