エントリに負荷がかかり、ページごとに 10 のエントリがあり、合計で約 130 ページのテーブルがあります。
ページングをメモリに保持しながら、同じビューでアクションを処理するにはどうすればよいですか...
@using (Html.BeginForm())
{
<label>All Logs since :</label> <input id="startDate" name="startDate" class="datepicker" type="text" value="@Model.option.startDate.Value.ToString("dddd, dd MMMM yyyy")" />
<input type="submit" />
}
これが提出されると、テーブルは開始日でフィルター処理されます。しかし、ユーザーがページ リンクをクリックした場合、ビューのデフォルト設定を上書きするには、この調査結果が必要です。コントローラーのアクションは次のとおりです。
[HttpGet]
public ActionResult Index(int? id)
{
MainViewModel model = new MainViewModel();
model.option = new LogOption();
model.option.numberOfResultPerPage = 10;
model.option.startDate = (method to set default date)
model.option.startPageIndex = id ?? 1;
*** call to service with the model.options as filter and set my table's column info and retreive the logs total in a custom class ( model.listing ) ***
model.totalPage = model.listing.TotalPages;
return View(model);
ユーザーが新しい日付を送信すると、まったく同じことを行いますが、デフォルトの日付をそのようなものに設定するという小さな違いがあります:
[HttpPost]
public ActionResult Index(LogOption mod)
{
model.option.startDate = mod.startDate;
}
問題は、startDate フィルターが変更された後、ユーザーがクリックしてテーブルからページを変更すると、get アクションが再度呼び出され、元のデフォルト設定の上書きを処理する方法がわからないことです。セッションで情報を設定することなく、よりクリーンな方法でそれを行うことができますか?
get info と一緒にモデルを渡す必要があると思いますが、それを行うことができませんでした。
[HttpPOST]
public ActionResult Index(MainViewModel mod, int? id)
{
}
しかし、これを行うとMainViewModelは常にnullになるため、セッションに保存する以外に両方の情報を取得する方法がわかりませんが、それを避けるように言われ、他の方法で行うことが可能でした