2012-01-06 8 views
0

現在、アイテムのリストを表示し、(同じページ上の)アイテムをフィルタリングできる単純なMVC 3アプリケーションを作成しています。ユーザーはアイテムをクリックし、詳細ページにリダイレクトされます。アイテムの詳細をクリックした検索結果に戻るMVC 3/C#

問題は、ユーザーが「リストに戻る」をクリックすると検索条件が失われ、現在のページ(検索結果がページングされている)が失われることです。

私はMVCを初めて使用しているため、これをどのように行うべきかを理解できないようです。

コントローラ

.... 
public ActionResult Index(PacketSearch search) 
{    
    const int pageSize = 20; 

    var allPackets = this.repository.GetAllPackets().Where(p => (string.IsNullOrEmpty(search.FromIp)) || p.FromIp == search.FromIp); 

    var pagedPackets = new PaginatedList<RawPacket>(allPackets, search.Page ?? 0, pageSize); 

    search.SearchResults = pagedPackets; 

    return View(search);    
} 

public ActionResult Details(int id) 
{ 
    var packet = this.repository.GetPacket(id); 

    return View(packet); 
} 

メインページ

....  
@if (Model.SearchResults != null && Model.SearchResults.Count > 0) 
{ 
    <table> 
     <tr> 
      <th> 
       Timestamp 
      </th> 
      <th> 
       From IP 
      </th> 
     </tr> 
     @foreach (var item in Model.SearchResults) { 
     <tr> 
      <td> 
       @Html.ActionLink(item.TimestampString, "Details", "Packets", new { id = item.Id }, null) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.FromIp) 
      </td> 
     </tr> 
     } 
    </table> 
} 
<br /> 
@if (Model.SearchResults.HasPreviousPage) 
{ 
    @Html.RouteLink("<<<", "Packets", new { page = (Model.SearchResults.PageIndex - 1) }) 
} 

Page @(Model.SearchResults.PageIndex + 1) of @Model.SearchResults.TotalPages 

@if (Model.SearchResults.HasNextPage) 
{ 
    @Html.RouteLink(">>>", "Packets", new { page = (Model.SearchResults.PageIndex + 1) }) 
} 

詳細ページ

<h2>Packet Details</h2> 

<fieldset> 
    <legend>RawPacket</legend> 

    <div class="display-label">Timestamp</div> 
    <div class="display-field"> 
     @Html.DisplayFor(model => model.TimestampString) 
    </div> 

    <div class="display-label">FromIp</div> 
    <div class="display-field"> 
     @Html.DisplayFor(model => model.FromIp) 
    </div> 
</fieldset> 
<p> 
    @Html.ActionLink("Back to List", "Index") 
</p> 

任意の助けも、感謝をいただければ幸いです。

答えて

0

あなたは入力をどこかに残す必要があります。そして、最適な場所はurlです(ユーザーがキャッシュして記憶できるため)。

検索の主な役割を果たす別のアクションをコントローラに定義し、検索パラメータをクエリ文字列を介して送信します。

関連する問題