ERROR上的FileResult + redirectToAction

时间:2014-12-18 17:35:40

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

当我呼叫网络服务获取凭证并且网络服务是KO时,我有时会出现错误。我需要重定向到另一个Action:我需要做这样的事情:

  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");
        }

    }

我该怎么做?

1 个答案:

答案 0 :(得分:0)

试试这个:

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