c# - RedirectToAction 不起作用

标签 c# model-view-controller

RedirectToAction 不显示 View 。

    // Go populate and display PDF using XML file
    DoPDF(stXML); 
}
UpDateDropDown(model);
return RedirectToAction("ReportsSelection", "Reports");

渲染代码:

private void DoPDF(String stXML)
{
    string filename = string.Concat(Guid.NewGuid().ToString(), ".pdf");
    PdfReader reader = new PdfReader(new RandomAccessFileOrArray(Request.MapPath(_NFCPage._NFReference.FM_NOFEAR_PDF)), null);
    // Create the iTextSharp document
    // Set the document to write to memory

    using (MemoryStream memStream = new MemoryStream())
    {
        PdfStamper ps = new PdfStamper(reader, memStream);
        // Populate the PDF with values in the XML file
        AcroFields af = ps.AcroFields;
        ParserXML(stXML, af);
        ps.FormFlattening = false;
        ps.Writer.CloseStream = false;
        ps.Close();
        byte[] buf = new byte[memStream.Position];
        memStream.Position = 0;
        memStream.Read(buf, 0, buf.Length);
        // Set the appropriate ContentType
        Response.ContentType = "Application/pdf";
        // Get the physical path to the file
        Response.AddHeader("Content-disposition", string.Format("attachment; filename={0};", filename));
        // Write the file directly to the HTTP content output stream.
        Response.Buffer = true;
        Response.Clear();

        Response.BinaryWrite(memStream.GetBuffer());  //Comment out to work
        Response.End();                               //Comment out to work
    }
}

我注意到,如果我删除 DoPDF 例程中的最后两行,它确实会显示 View 。

最佳答案

Response.End() 将导致服务器发送 HTTP 响应。此时您的浏览器将认为请求已完成并且不会发生重定向。你能提供更多关于你想要完成的事情的背景吗?然后我们可以更好地了解如何为您提供帮助。

关于c# - RedirectToAction 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9086967/

相关文章:

C# 从 List<KeyValuePair<string, string> 获取键和值

c# - 如何计算一个位置与另一个位置之间的距离/接近度(c#)

ios - MVC 中的附加类

ios - MVC——弥合我的模型和它在屏幕上的表现之间的差距

c# - C# 中的结构

c# - 无法删除该对象,因为在 ObjectStateManager 中找不到它

c# - MS 图表控件 : Formatting Axis Labels

model-view-controller - asp.net MVC ActionFilter 用于删除结果中的空行

iphone - 如何从当前 View Controller 的实现文件加载另一个 View Controller ?

objective-c - 触摸时 UISegmentedControl 索引不更新