【发布时间】:2012-10-12 09:42:37
【问题描述】:
我在控制器中有两个动作:
public ActionResult ReportRequest()
{
return View();
}
[HttpPost]
public ActionResult Report(ReportRequestObj rr, FormCollection formValues)
{
if (Request.HttpMethod != "POST")
return RedirectToAction("ReportRequest");
ReportingEngine re = new ReportingEngine();
Report report = re.GetReport(rr);
return View(report);
}
我的问题是,“报告”页面的 URL 保存在浏览器中,当我点击它时,我得到一个 404,因为请求尚未发布。
我放入了一个处理程序以重定向到报告请求页面,但是在调试时它似乎根本没有遇到这个问题。
有没有其他方法可以确定请求是否为帖子,如果不是则重定向回另一个页面?
谢谢
【问题讨论】:
-
删除方法顶部的 [HttpPost],您可以检查 if (Request.HttpMethod != "POST") return RedirectToAction("ReportRequest");它是否应该返回。
标签: c# asp.net-mvc http-post