2017-12-27 4 views
2

Requirementumbraco 및 C# 면도기 : 모델

에서 페이지에 partialview 또는 뷰에 짝수와 홀수 vlaue alternativelty을 인쇄하는 방법을 나는 왼쪽 이미지 & 내용과 오른쪽 이미지 & 내용에 대한 두 개의 HTML을 가지고있다. 가치있는 인쇄. 내가 무엇을 쓸 수있는 각각의 루프 홀수 및 짝수 값을 페이지의 부분보기에서 모델에서 인쇄합니다.

@inherits UmbracoViewPage<List<ProjectName.Models.DealerSectionModel>> 
 
    @using ProjectName.Models; 
 
    @using Umbraco.Core; 
 
    
 
    
 
    @{ 
 
     foreach (DealerSectionModel historylist in Model) // what should i write in this loop .(ex if 1 value in model then print odd html) 
 
     { 
 
      if() 
 
      { 
 
       @RenderEvenHistoryList(historylist) 
 
      } 
 
      else 
 
      { 
 
       @RenderOddHistoryList(historylist) 
 
      } 
 
      
 
     } 
 
    } 
 
    
 
    @helper RenderOddHistoryList(DealerSectionModel item) 
 
      { 
 
      <div class="row history-second-section py-2 py-xl-4 py-lg-4 py-md-4 py-sm-2"> 
 
       <div class="col-12 col-xl-6 col-lg-6 col-md-6 col-sm-12 history-second-images"> 
 
        <div class="quote my-3"><iframe src="@item.VideoUrl" width="510" height="282" frameborder="0" allowfullscreen></iframe></div> 
 
       </div> 
 
       <div class="col-12 col-xl-6 col-lg-6 col-md-6 col-sm-12 history-second-content"> 
 
        <div class="content-year">@item.Title </div> 
 
        <h4>@item.ImageTitle</h4> 
 
        <p>@item.ImageDescription</p> 
 
        
 
       </div> 
 
      </div> 
 
    
 
    } 
 
    
 
    } 
 
    
 
    @helper RenderEvenHistoryList(DealerSectionModel item) 
 
      { 
 
     // render html for even model value 
 
    } 
 
    
 
    }

답변

3

내가 umbraco에 대해 많이 알고 있지만, 왜이

@ {INT 수처럼 할 수있는 간단한 일처럼

@{ 
    var even = false; 
     foreach (DealerSectionModel historylist in Model) // what should i write in this loop .(ex if 1 value in model then print odd html) 
     { 
      if (even) 
      { 
       @RenderEvenHistoryList(historylist) 
      } 
      else 
      { 
       @RenderOddHistoryList(historylist) 
      } 
      even = !even; 
     } 
    } 
+0

감사합니다! –

1

을 시도하지 말라 = 1;

foreach (DealerSectionModel historylist in Model) 
{ 
    if (count % 2 == 0) 
    { 
     @RenderEvenHistoryList(historylist) 
    } 
    else 
    { 
     @RenderOddHistoryList(historylist) 
    } 
    count++; 
} 

} 작동

+1

너도 내 친구 야! 감사 –