在常规MVCController中,我们可以使用FileContentResult输出pdf。publicFileContentResultTest(TestViewModelvm){varstream=newMemoryStream();//...addcontenttothestream.returnFile(stream.GetBuffer(),"application/pdf","test.pdf");}但是我们怎样才能把它变成一个ApiController呢?[HttpPost]publicIHttpActionResultTest(TestViewModelvm){//..
在常规MVCController中,我们可以使用FileContentResult输出pdf。publicFileContentResultTest(TestViewModelvm){varstream=newMemoryStream();//...addcontenttothestream.returnFile(stream.GetBuffer(),"application/pdf","test.pdf");}但是我们怎样才能把它变成一个ApiController呢?[HttpPost]publicIHttpActionResultTest(TestViewModelvm){//..
我正在编辑一些代码,有一种方法返回FileContentResult类型。我从服务中获取流,所以对我来说,将返回类型更改为FileStreamResult会更方便。我应该将流转换为数组以返回FileContentResult吗?或者我可以安全地更改返回类型吗? 最佳答案 FileStreamResult和FileContentResult都继承自FileResult,FileResult继承自ActionResult。因此,您可以从以ActionResult作为返回类型的方法返回任何一种类型如果您已经有一个流,您可以使用FileSt