我有一個表入口負載,每頁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;
}
的問題是,如果起始日期過濾器後已被修改,如果用戶點擊該網頁從我的表變化,取得動作被再次調用,我不知道如何處理原來的默認設置的首要。我可以以更清潔的方式做到這一點,而不必在會話中設置信息?
我想我需要通過模型與獲取信息,但我還沒有能夠做到這一點。
[HttpPOST]
public ActionResult Index(MainViewModel mod, int? id)
{
}
但我MainViewModel總是空當我這樣做,所以我不知道如何從保存它在會話一邊同時獲得信息,但我被告知要避免這一點,這是可以做到這一點其他way
貴MainViewModel有一個參數的構造函數?我同意最後一種方法:使用模型和其他參數進行1次GET操作。 – Cam
@Cam我不能這樣做,我的mainviewmodel總是設置爲空...我沒有在其中設置任何構造函數,它主要只是3自定義對象(用戶配置文件,日誌列表和篩選器選項)和3自定義對象沒有任何構造器(也就是mvc4默認設置的用戶配置文件,所以它可能有,但還沒有它的工作) –
也許這會有所幫助,但可能不會:記得在你的視圖中設置模型類型。 – Cam