Asp.net mvc 4 返回ASP MVC4 Webapi中包含流的模型

Asp.net mvc 4 返回ASP MVC4 Webapi中包含流的模型,asp.net-mvc-4,stream,asp.net-web-api,Asp.net Mvc 4,Stream,Asp.net Web Api,我的模型课看起来像这样 public Stream FileStream { get; set; } public string FileName { get; set; } public string ContentType { get; set; } 是否可以将此模型返回到webapi?流只是指向某个实际资源的指针。如果您想将其发送到响应并能够对其进行序列化,可以使用字节数组 或者更好,将流写入响应,然后对其他两个属性使用标准HTTP头: Content-Type: application

我的模型课看起来像这样

public Stream FileStream { get; set; }
public string FileName { get; set; }
public string ContentType { get; set; }

是否可以将此模型返回到webapi?

流只是指向某个实际资源的指针。如果您想将其发送到响应并能够对其进行序列化,可以使用字节数组

或者更好,将流写入响应,然后对其他两个属性使用标准HTTP头:

Content-Type: application/pdf
Content-Disposition: attachment; filename=report.pdf

... the actual content comes here

您也可以考虑编写一个自定义来实现这一点,如

< P>不。这不能自动序列化。但是返回一条流很容易。看