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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: