MVC 3. VB.NET我在我的應用程序中通過下載將生成的PDF文件發送給用戶時有以下控制器操作。當控制器本身被調用時,該函數可以正常工作。但是,當我從控制器外部調用函數時,只要它碰到response.contenttype行,就會返回「對象引用未設置爲對象的實例」錯誤。我已經驗證了所有的變量都在事實上,它使以下面的動作......但沒有骰子,如果我嘗試在其他控制器稱之爲:HttpResponse對象空錯誤
Dim _print as new PrintController
_print.showUserPDF(firstName,lastName)
return RedirectToAction("Registrants")
在PrintController功能是引發錯誤是:
Function showUserPDF(ByVal pdfName As String, ByVal fileName As String, ByVal _directory As String) As ActionResult
If Not String.IsNullOrEmpty(pdfName) Then
Response.ContentType = "application/pdf"
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName)
Response.TransmitFile(pdfName)
Response.[End]()
Dim FileToDelete As String
FileToDelete = pdfName
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
Directory.Delete(_directory)
Return Nothing
End If
Return Nothing
End Function
任何想法,爲什麼這隻有在明確從它的包含控制器內部調用時才起作用?