Home > OS >  Razor-Pages - HTML markup
Razor-Pages - HTML markup

Time:10-01

Following the answer on this enter image description here

  • The intellicode gets all messed up (I only deleted the paragraph on the second @:)

enter image description here

  • Also, my if (i == (Model.CellsNotStarted.Count - 1) && i % 2 != 0) won't work when using the @:; it will always go on the else. If I don't use the @: markup, and if I, for instance put all my html in a if/else instead of only the <div> tag it will work with no problems.

My question is: Is the @: markup viable? If so, what am I doing wrong. If not what is the alternative (that does not imply putting my entire code in an if/else)

PS: I know I should not post images of code, but I wanted to show the format and syntax errors.

CodePudding user response:

There are neater ways to manage conditions within your Razor code. It's difficult to provide a full example because you don't provide the full code, but you can do this, for example:

<div class="col-md-@(i 1 == Model.CellsNotStarted.Count && i % 2 ! = 0 ? "12" : "6")">

Whenever you are tempted to use a remainder operator (%) in Razor, you should also consider whether a GroupBy would be better. It most often is, as I was shown in this question: enter image description here

  • Related