Home > Net >  MVC webapi FileResult file interface is how to return to the interface when the file is empty
MVC webapi FileResult file interface is how to return to the interface when the file is empty

Time:09-26

By an interface to database query data, if no not query to the results,
Actually, there is no files are generated is returned to the front end, how to return to the interface shows that there is no data?

Test returns a
Return the File (new byte [0], "text/plain", "welcome. TXT");
The browser will download file,

CodePudding user response:

Can't front end development consultation, if the byte [0], do not download?

CodePudding user response:

Just want to talk to JsonResult yes, there is the object can be returned to the front record number, success, etc., can return to additional information,
And FileResult zha return to other information, is intended to hit if there is no data, do not need to return the file record number=0 at this time

CodePudding user response:

Depending on your logic, you can return NoContent (); Or return NotFound (); They are all IActionResult,

If (File) return the File (new byte [0], "text/plain", "welcome. TXT");
The else return NoFound ();

CodePudding user response:

NoContent ()
Zha tip without using NotFound ()
  • Related