开发者

how to return a FileResult from a string in asp.net mvc

开发者 https://www.devze.com 2022-12-14 11:17 出处:网络
I need to write an action that will return a FileResu开发者_运维知识库lt from a string You can use the FileContentResult class.

I need to write an action that will return a FileResu开发者_运维知识库lt from a string


You can use the FileContentResult class.

        var contentType = "text/xml";
        var content = "<content>Your content</content>";
        var bytes = Encoding.UTF8.GetBytes(content);
        var result = new FileContentResult(bytes, contentType);
        result.FileDownloadName = "myfile.xml";
        return result;
0

精彩评论

暂无评论...
验证码 换一张
取 消