ASP.NET MVC 4 FileResult - In error
asp.net, asp.net-mvc, asp.net-mvc-4, c#
Solution
I would change the return type of your method to ActionResult.
public ActionResult GetReport(string id)
{
byte[] fileBytes = _manager.GetReport(id);
if (fileBytes != null && fileBytes.Any()){
string fileName = id+ ".pdf";
return File(fileBytes, MediaTypeNames.Application.Octet, fileName);
}
else {
//do whatever you want here
return RedirectToAction("GetReportError");
}
}
Problem
I have a simple Action on a controller which returns a PDF. Works fine. ``` public FileResult GetReport(string id) { byte[] fileBytes = _manager.GetReport(id); string fileName = id+ ".pdf"; return File(fileBytes, MediaTypeNames.Application.Octet, fileName); } ``` When the manager fails to get the report I get back `null` or an empty `byte[]`. How can I communicate to the browser that there was a problem, when the result is set to a `FileResult`?