我有一個帶有Index方法的控制器,它有幾個可選參數用於過濾返回到視圖的結果。MVC3:帶搜索過濾器的PRG模式行動方法
public ActionResult Index(string searchString, string location, string status) {
...
product = repository.GetProducts(string searchString, string location, string status);
return View(product);
}
我想實現像下面的PRG模式,但我不知道如何去做。
[HttpPost]
public ActionResult Index(ViewModel model) {
...
if (ModelState.IsValid) {
product = repository.GetProducts(model);
return RedirectToAction(); // Not sure how to handle the redirect
}
return View(model);
}
我的理解是,你不應該使用這個模式,如果:
- 你並不需要使用這種模式,除非你有實際存儲一些數據(我不是)
- 你不會使用這種模式來避免在刷新頁面時出現「確定要重新提交」消息(有罪)
我應該試圖使用這種模式嗎?如果是這樣,我該怎麼辦呢?
謝謝!
我肯定會使用這個模式,以避免對即對話「你不會使用這種模式避免了‘你確定你想要的’刷新頁面時(犯)從IE消息」,以重新提交其一般不鼓勵最終用戶,他們通常不知道該怎麼做「我點擊取消嗎?我點擊好嗎?啊!太多的決定!!」 –