Copied to clipboard

Flag this post as spam?

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


  • Kate 267 posts 610 karma points
    Oct 02, 2013 @ 11:24
    Kate
    0

    Simple for loop

    Hi

    I have this very simple loop that I can not get to count 1 up.

    Here is my loop

    @for(var i =1; i < 5; i++)
    {
    <p>@Model.item + @i</p>
    }

    The "item" is a property on a doctype
    The properties are called item1, item2 ,item3, item4

    I just need it to spit out the content from my properties.
    How do I do that? :-)


    /Kate

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Oct 02, 2013 @ 11:55
    Alex Skrypnyk
    0

    Hi Kate,

    Yo can use something like that:

    @foreach (var prop in Model.GetType().GetProperties())
    {
      <p>@prop.Value</p>
    }
    

    Thanks, Alex

  • Kate 267 posts 610 karma points
    Oct 02, 2013 @ 12:37
    Kate
    0

    HI Alex

    Im not sure I can use that, but maybe that is becaurse I dont understand the code
    What does Model.GetType().GetProperties means?

    In my doctype called TekstSide I have these properties

    And these are the items that I want to loop through :-)



     

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Oct 02, 2013 @ 14:48
    Alex Skrypnyk
    100
    @for(var i =1; i < 5; i++)
    {       
        <p>@Model.GetPropertyValue("item" + i)</p>
    }
    

    Something like that ) Thanks

  • Kate 267 posts 610 karma points
    Oct 02, 2013 @ 15:42
    Kate
    0

    Yes :-)

    Thanks, great help :-)

Please Sign in or register to post replies

Write your reply to:

Draft