开发者

Returning a file in a new browser window using mvc 3 razor vb.net

开发者 https://www.devze.com 2023-04-12 18:26 出处:网络
I have a function that returns a generated PDF file but the problem is it shows it in the current browser window... I need for it to open in a new window. I dont see how I can pass it into a view for

I have a function that returns a generated PDF file but the problem is it shows it in the current browser window... I need for it to open in a new window. I dont see how I can pass it into a view for displaying where I could simply use target: _blank. Any Ideas?

     Function sho开发者_如何学编程wUserPDF(ByVal pdfName As String) As ActionResult
        Dim _fileName As String = pdfName
        Dim _path As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\PDF_Files\"
        Response.AppendHeader("Content-Disposition", "inline; filename=" + _fileName + ";")

        Return File(_path + _fileName, System.Net.Mime.MediaTypeNames.Application.Pdf, _fileName)

    End Function


You can't control the window from server-side code - you need to launch the original request targetting a new window, eg.:

Html.ActionLink("Text", "Action", null, new { target="_blank" })

If the request comes from a redirect, then the original request before the redirect would need to be opened in the new window.

You could also use Content-Disposition: attachment header to force the browser to prompt to download.

0

精彩评论

暂无评论...
验证码 换一张
取 消