c# - FileResult + redirectToAction出现错误

标签 c# asp.net-mvc-4 redirect error-handling

有时我在调用Web服务以获取凭证且Web服务为KO时出现错误。我需要重定向到其他操作:我需要执行以下操作:

  public virtual FileResult Ticket(int operationCategoryId, int orderId)
    {
        try
        {
            var orderDetail = _orderDetailBusiness.GetOrderDetail(operationCategoryId, orderId);
            byte[] ticketContent = _vpTicketMinuteBusiness.GetTicketContent(orderDetail.Parcels);
            return File(ticketContent, "application/pdf", orderId + ".pdf");
        }
        catch (NullReferenceException exception)
        {
            return RedirectToAction("Error");
        }

    }

我怎样才能做到这一点?

最佳答案

尝试这个:

 return new FileStreamResult(ms, "application/ms-excel")
            {
                FileDownloadName = "yourfile.xlsx",
            };

关于c# - FileResult + redirectToAction出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27552460/

相关文章:

c# - 无密码进入SQL Server

c# - 并发插入数据库

c# - 如何将自定义日志存储在使用diagnostics.wadcfg创建的Azure本地存储中

asp.net-mvc-4 - 使用 HTML.ActionLink 调用 Post 方法

asp.net-mvc-4 - IISExpress 崩溃并出现 0xc0000008 错误

php - 从 MySQL 中的列中获取每一行并在每个域上 curl 并使用新获取的域更改行

ubuntu - 如何使用 ssl Apache 将 www.subdomain 重定向到子域

c# - .Net 核心词典文档

.htaccess - 当新页面具有相同的 url 结构时进行 301 重定向

c# - 如何在 UserControl Paint 事件中对点进行动画处理?