Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    Jun 13, 2012 @ 11:22
    Kasper Dyrvig
    0

    Razor alternative for Xpath operator "mod"

    Hi

    I'm looking for the razor alternative for the Xpath operator "mod".

    In XSLT I use it like this:

    <xsl:if test="position() mod $groupNumber = 1"><xsl:attribute name="class">firstInRow</xsl:attribute></xsl:if>

    How can that be done in Razor? Thanks in advance...

  • Sören Deger 733 posts 2844 karma points c-trib
    Jun 13, 2012 @ 15:13
    Sören Deger
    0

    Hi,

    the razor alternative for the Xpath operator "mod" is "%"

    Example:
    int pos=0;
    foreach(var item in @Model.Children.Where("Visible"))
    {
       pos++;
       if(pos % groupNumber == 1)
       {
          //your code here...
       }
    }

  • Kasper Dyrvig 246 posts 379 karma points
    Jun 13, 2012 @ 15:27
    Kasper Dyrvig
    0

    Yes! Great! Thanks

  • 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