2012-02-25 159 views
0

我有一個IEnumerable類型的集合。我想表明它是這樣的:將Ienumerable分爲兩部分

一)按日期得到收集第一個元素和標題1 b在顯示)反向剩餘的收集和顯示標題2.

繼下的所有剩餘的元素是什麼,我創建

<ul style="list-style-type: none;"> 
    @{ 

     var responses = dispute.DisputeTransactions.GetTransactionByLogOnType(((CreditRegistryPrincipal)User).LogOnType); 
     var first = responses.OrderBy(dd => dd.TransactionDate).FirstOrDefault(); 
     responses = responses.OrderByDescending(dd => dd.TransactionDate); 
    } 
    @if (dispute.Response > 0) 
    { 
     <h3 style="margin-left: -15px; margin-bottom: 10px;"> 
      Responses and Feedbacks</h3> 
    } 
    @foreach (DisputeTransaction dt in responses) 
    { 
     if (dt.DisputeTransactionId == first.DisputeTransactionId) 
     { 

      // firstConversation = false; 
     <h3 style="margin-bottom: 10px"> 
      Dispute</h3> 
     <ul class="firstConversation" style="margin-left: -15px"> 
      <div class="dispute-notes"> 
       @dt.Notes 
      </div> 

     </ul> 

     } 
     else 
     { 
      // responses = responses.SkipWhile(dd => dd.DisputeTransactionId == first.DisputeTransactionId); 



     <li class="dispute-item @(user.RegistryID == dt.ReportedById ? "mine" : "their")"> 
      <div> 
       <span class="dispute-writter"><b>@dt.ReportedBy.FullName</b> on @CreditRegistryRepository.FormatDateTime(dt.TransactionDate) 
        wrote:<br /> 
       </span> 
       <div class="dispute-content"> 
        <div class="dispute-notes"> 
         @dt.Notes 
        </div> 

       </div> 
      </div> 
     </li> 
     } 
    } 
</ul> 

但它顯示在底部的標題1。如何使標題一和第一個元素在頂部。請建議

回答

1

你總是可以嘗試空兩排序依據的,以及

var responses = dispute 
        .DisputeTransactions 
        .GetTransactionByLogOnType(((CreditRegistryPrincipal)User).LogOnType) 
        .OrderBy(dd => dd.TransactionDate); 
var first = responses.FirstOrDefault(); 
responses = responses.Skip(1).Reverse(); 

反向將永遠比最快的一個OrderBy


@{ 
    var responses = new List<string>() { "1", "2", "3", "4", "5" }; 
    var first = responses.First(); 
    var allButOne = responses.Skip(1).Reverse(); 
} 
<h1>@first</h1> 
<ul> 
    @foreach (var a in allButOne) 
    { 
     <li>@a</li> 
    } 
</ul> 

enter image description here

0

只是不要在循環使用它作爲你遍歷降序收集

<ul style="list-style-type: none;"> 
@{ 

    var responses = dispute.DisputeTransactions.GetTransactionByLogOnType(((CreditRegistryPrincipal)User).LogOnType); 
    var first = responses.OrderBy(dd => dd.TransactionDate).FirstOrDefault(); 
    responses = responses.OrderByDescending(dd => dd.TransactionDate); 
} 
@if (dispute.Response > 0) 
{ 
    <h3 style="margin-left: -15px; margin-bottom: 10px;"> 
     Responses and Feedbacks</h3> 
} 

<h3 style="margin-bottom: 10px"> 
    Dispute</h3> 
<ul class="firstConversation" style="margin-left: -15px"> 
    <div class="dispute-notes"> 
     @dt.Notes 
    </div> 
</ul> 
@foreach (DisputeTransaction dt in responses) 
{ 
    if (dt.DisputeTransactionId != first.DisputeTransactionId) 
    { 
     // responses = responses.SkipWhile(dd => dd.DisputeTransactionId == first.DisputeTransactionId); 



    <li class="dispute-item @(user.RegistryID == dt.ReportedById ? "mine" : "their")"> 
     <div> 
      <span class="dispute-writter"><b>@dt.ReportedBy.FullName</b> on @CreditRegistryRepository.FormatDateTime(dt.TransactionDate) 
       wrote:<br /> 
      </span> 
      <div class="dispute-content"> 
       <div class="dispute-notes"> 
        @dt.Notes 
       </div> 

      </div> 
     </div> 
    </li> 
    } 
}