相关疑难解决方法(0)

MVC3:PRG模式与行动方法的搜索过滤器

我有一个带有Index方法的控制器,该方法有几个可选参数,用于过滤返回到视图的结果.

public ActionResult Index(string searchString, string location, string status) {
    ...

product = repository.GetProducts(string searchString, string location, string status);

return View(product);
}
Run Code Online (Sandbox Code Playgroud)

我想像下面这样实现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);
}
Run Code Online (Sandbox Code Playgroud)

我的理解是,如果出现以下情况,则不应使用此模式:

  • 您不需要使用此模式,除非您实际存储了一些数据(我不是)
  • 在刷新页面时,您不会使用此模式来避免IE中的"您确定要重新提交"消息(有罪)

我应该尝试使用这种模式吗?如果是这样,我该怎么做呢?

谢谢!

asp.net-mvc-3

1
推荐指数
1
解决办法
1363
查看次数

标签 统计

asp.net-mvc-3 ×1