【发布时间】:2012-05-17 00:28:24
【问题描述】:
我有一个带有 Index 方法的控制器,它有几个可选参数用于过滤返回到视图的结果。
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 的“您确定要重新提交”消息(有罪)
我应该尝试使用这种模式吗?如果是这样,我将如何处理?
谢谢!
【问题讨论】:
-
我肯定会使用这种模式来避免 IE 对话框“你不会使用这种模式来避免刷新页面时来自 IE 的“你确定要重新提交”消息(有罪)”它通常不鼓励最终用户,他们通常不知道该怎么做“我点击取消吗?我点击确定了吗?啊!太多的决定!”
标签: asp.net-mvc-3