PDA

View Full Version : [CLOSED] PDF file result from MVC



registrator
May 14, 2015, 11:28 AM
Do you perhaps have an example of returning a PDF file from an MVC action on Direct Event button click?
I am struggling to make this.
It is a button on a window that should present a user with a PDF file.

THank you

Daniil
May 14, 2015, 9:47 PM
Hi @registrator,

I was unable to find such an example. Though, it doesn't mean that it doesn't exist on the forums.

Anyways, this might help.
http://stackoverflow.com/questions/1510451/how-to-return-pdf-to-browser-in-mvc

registrator
May 14, 2015, 10:02 PM
OK, thanks Daniil, let me try to put something together and I'll come back if I have some queries.

registrator
May 17, 2015, 6:36 PM
Can you please try this scenario:

I have used your 2013 V3 examples solution and in the example "Window_Basic/Hello_World" I have added a button on a window:



@(X.Window()
.ID("Window1")
.Title("Hello World")
.Icon(Icon.Application)
.Height(185)
.Width(350)
.BodyStyle("background-color: #fff;")
.BodyPadding(5)
.Modal(true)
.Content(c => "This is my first <a target='_blank' href='http://www.ext.net/'> Ext.NET</a> Window.")
.Buttons(
X.Button().Text("Save")
.DirectEvents(de =>
{
de.Click.Url = Url.Action("Save");
}
)
)

)


In the controller I had the following

public ActionResult Save()
{
string pdfFileName = Server.MapPath("~/PDFTempFiles/Test.pdf");
return this.File(pdfFileName, "application/pdf", "Test.pdf");
}

And got this:



Status Code: 200Status Text: BADRESPONSE: Unexpected token %


Seems like Ext.NET does not like this type of action result.

While in the window you can see that it is the PDF returned. See attachment.23979

Daniil
May 19, 2015, 10:48 AM
At least, you should set

de.Click.IsUpload = true;

This might be helpful.
http://forums.ext.net/showthread.php?27549-Upload-File-using-DirectEvent

registrator
May 19, 2015, 12:12 PM
Hi Daniil

Thank you for answering. This is not upload I am referring to but a download of a pdf file.

Daniil
May 19, 2015, 1:00 PM
Oh, sorry. This might help then.
http://forums.ext.net/showthread.php?27575