mardi 29 septembre 2015

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.

However after the initial 'if' statement worked the second if statement outputs to my page as 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. I'm probably missing something really obvious - but any help would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire