【问题标题】:Which class does this c# File belongs to这个c#文件属于哪个类
【发布时间】:2020-03-26 09:38:33
【问题描述】:

我正在尝试通过 ActionResult 返回文件内容。但是,我找不到 File() 函数属于哪个库。所以 File(..) 无效。文件属于哪个库?我需要添加它。它属于 system.web.mvc 吗?但我在 System.Web.Mvc 中找不到文件。

[HttpGet]
        public virtual ActionResult Download(string fileGuid,string fileName)
        {
            Guid guid = new Guid(fileGuid);
            if (store[guid].Ready != 0)
            {
                byte[] data = store[guid].Data as byte[];

                // The File here is not valid, I can't find which library it belong to
                return File(data, "application/vnd.ms-excel",fileName);
            }
            else
            {                   
                return new EmptyResult();
            }
        }

【问题讨论】:

    标签: c# asp.net file actionresult


    【解决方案1】:

    这可能取决于确切的目标框架,但是:Microsoft.AspNetCore.Mvc.ControllerBase 上有一系列 public virtual FileContentResult File(...) 重载应该可用如果您的控制器继承自该框架。或者,您可以直接使用new FileContentResult(...),从Microsoft.AspNetCore.Mvc - 全部在Microsoft.AspNetCore.Mvc.Core.dll

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多