我有一个带有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)
我的理解是,如果出现以下情况,则不应使用此模式:
我应该尝试使用这种模式吗?如果是这样,我该怎么做呢?
谢谢!