FileResult in controller and returning NotFound

Return NotFound() in FileResult. Just change return type to ActionResult, because FileResult inherits from ActionResult. And then it is possible to return NotFound() e.g. when object equals null.

So FileResult -> ActionResult, something like this:

public FileResult ActionResult GetFile(int id)
 {
         var file = await service.Get();
         if(file == null) 
         {
             return NotFound();
         }
         …
         return File(…);
 }

Leave a comment