I download a file from an action which looks like this:
[HttpPost]
public override FileContentResult Foo() {
var someDataAsBytes = ...
return File(someDataAsBytes, "text/csv", "somefilename.csv");
}
The view has a form, which POSTs to this action.
I initiate the download in script, so that the page doesn't change:
$(myForm).on("submit", function() {
window.location.href = $(this).attr("action");
});
The file is downloaded correctly.
But, my Elmah logs show that there was a "no matching action" error.
If I use [HttpHead]
, [HttpPost]
or [HttpGet]
, I get the same result. If I remove the HTTP method, then I don't get an error.
Ideally I'd like to use POST, but that's not crucial. How do I restrict the action to one of these, but not get errors?