Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James Feeney 26 posts 166 karma points
    Sep 12, 2013 @ 14:48
    James Feeney
    0

    Razor If conditional super quick syntax check

    Can someone quickly tell me if my syntax is correct for these conditions in my If statement in Razor?

    var item = (an incremental number);
    var rows = (an incremental number);
    var numInRow = (guess what, an incremental number!);
    if (item % numInRow == 0 && rows == 1) { }

    I've checked it with just rows == 1 and that works.
    So its really the item % numInRow == 0 part thats causing the error. (Checking to see if item is a multiple of numInRow).

    Thanks!

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Sep 12, 2013 @ 21:23
    Dan Diplo
    1

    Assuming item, numInRow and rows are  all integers then your syntax is fine. What error are you getting?

  • Charles Afford 1163 posts 1709 karma points
    Sep 14, 2013 @ 12:06
    Charles Afford
    0
    int item =(an incremental number);
    int rows =(an incremental number);
    int numberInRow =(guess what, an incremental number!);

    if(item % numInRow ==0&& rows ==1){
       }

    I am sure that % is something diffrent. What does int test = item % numInRow; give you?
    You do not need to use var i dont think you the type you know will be returned. 
  • James Feeney 26 posts 166 karma points
    Oct 14, 2013 @ 10:35
    James Feeney
    100

    Sorry for delayed reply.  I discovered another way of acheiving what I needed. However, I think it's now irrelevent to this issue! But thank you for your help. I now make sure I'm declaring the type instead of just using var.

  • Funka! 398 posts 661 karma points
    Oct 16, 2013 @ 04:48
    Funka!
    0

    A fun, but apparently well-hidden and non-documented alternative, is to use the InGroupsOf method which can make your code a little easier to read and write. Helpful-looking blog post here in lieu of any official documentation : http://www.simonantony.net/knowledge-base/articles/grouping-nodes-in-umbraco-razor/

    Good luck!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies