c# - foreach where data flips sides every other -


is possible say: if image on left next 1 should on right, repeat until done?

pseudo code:

@foreach (var item in model.items) {     if (previous class=imageleft)     {         <div class="imageright">right image</div>         <div>left content</div>     }     else     {         <div class="imageleft">left image</div>         <div>right content</div>     } } 

yes, of course. you're pseudo code there. use variable hold value , remember update value in each iteration:

@int c = 0; @foreach (var item in model.items) {     if (c == 0)     {         <div class="imageright">right image</div>         <div>left content</div>         c = 1;     }     else     {         <div class="imageleft">left image</div>         <div>right content</div>         c = 0;     } } 

alternatively, can use @foreach (int = 0; < model.items.count; i++) loop , use i % 2 even/odd row numbers , apply class like.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -