0

I have two actions in a controller:

    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);
    }

My problem is, the URL for the 'Report' page gets saved in the browser, and when I click on it, I get a 404, because the request has not been posted.

I put in a handler in to redirect to the report request page however on debugging it just doesn't seem to hit this at all.

Is there any other way I can determine if the request is a post, and if not redirect back to another page?

Thanks

1
  • 2
    Remove the [HttpPost] on top of the method, and you can check with your if (Request.HttpMethod != "POST") return RedirectToAction("ReportRequest"); if it should return or not. Commented Oct 12, 2012 at 9:47

2 Answers 2

2

Add action

public ActionResult Report()
{
    return RedirectToAction("ReportRequest");
}

or just remove [HttpPost] from action Report

Sign up to request clarification or add additional context in comments.

Comments

0

You cannot handle 404 error here because that request will never arrive to your action. You are using an action filter that makes sure that only POST requests arrive to that piece of code.

You should create another action method to respond to GET requests and return your view inside that.

[HttpGet]
public ActionResult Report()
{
    return View("ReportRequest");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.