类型FileResult和FileStreamResult是未定义的,我该如何解决?

时间:2012-07-25 14:03:06

标签: asp.net-mvc vb.net

自昨晚以来,我一直在关注这个问题,并且无法弄清楚如何解决它。

2个错误,一个说,Type FileResult is not defined

另一个说,Type FileStreamResult is not defined

Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Text
Imports EO.Pdf
Imports System.Collections.Specialized

Partial Class getRecs
    Inherits System.Web.UI.Page

Public Function Download() As FileResult
        ' Populate list with urls 
        Dim qParams As String = Request.QueryString("p")
        Dim urls() As String = qParams.Split(","c, ChrW(StringSplitOptions.RemoveEmptyEntries))

        Dim documents = New List(Of EO.Pdf.PdfDocument)()
        For Each url In urls
            Dim doc = New EO.Pdf.PdfDocument()
            EO.Pdf.HtmlToPdf.ConvertUrl(url, doc)
            documents.Add(doc)
        Next

        Dim mergedDocument As EO.Pdf.PdfDocument = EO.Pdf.PdfDocument.Merge(documents.ToArray())

        Dim ms = New MemoryStream()
        mergedDocument.Save(ms)
        ms.Position = 0

        Return New FileStreamResult(ms, "application/pdf") With { _
         .FileDownloadName = "download.pdf" _
        }
    End Function

End Class

提前致谢。

2 个答案:

答案 0 :(得分:2)

FileResultFileStreamResult都需要以下参考:

System.Web.Mvc

答案 1 :(得分:1)

我希望你错过了

Imports System.Web.Mvc

可能是对System.Web.Mvc程序集的引用。 VS提供程序是否会对未添加此符号的未定义符号进行一点下拉? (我很少使用VB,所以不确定你是否和C#一样。)

但是对于ASP.NET WebForms,您可能会发现HttpResponse.WriteFile更好的方法。