c# - Return File not returning pdf correctly MVC 5 -


I am currently using a PDF server side PDF library. When this is done I try to return this PDF to the user.

Every time I try to fail to open PDF, or if I run it down as a download, it downloads as a corrupted file. If I type the physical address of the PDF in the browser, it loads properly.

In my Controller:

Return file (nfilePath, "application / pdf");

In this example, nfilePath = ~ / PdfStore / CurRep103323842.pdf

This is something stumped on this simple, any advice would be great. Thank you.

See part of that load

  @modelprintShiftHandover. Model ShiftHandOver @ {ViewBag.Title = "ShiftHandOver"; } & Lt; Div id = "updateRegion" & gt; @ {Html.RenderAction ("_ ReportDetails");} & lt; / Div & gt;   

See partial @Model PrintShiftHandover Models. Main report: DEFET @ {layout = string Empty; } & Lt; Div id = "PartialView" & gt; @ Use (Html.BeginForm ()) {

............. here a form

 } & lt; / Div & gt;   

Controller

  [http.post] Public functioning _ Description of report (Model Main Report Model Model) {var getfile = new CreatePdf (); Var nfilePath = getfile.getfile (model); Return file (nfilePath, "App / PDF"); } Catch (Exception preceded by {ModelState.AddModelError ("", ex.Message); See Return (Model); }}   

Built-in PDF generates HTML generated from the main view, which has PDF encoding inside Div Update.

You are calling @ html.RenderAction inside your output Essentially embedding PDF file

You need to replace that location with a button / link instead, which calls on @ Html.ActionLink is. Then change the line that says:

  @ {Html.RenderAction ("_ ReportDetails")}}   

with:

  @html Optional ("_ _ _ _ _ _">)   

Alternatively, you can add a meta refresh tag or jQuery to emphasize the file download.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -