Try our conversational search powered by Generative AI!

Change response type in block controller

Vote:
 

Hello everyone,

I'm trying to create a block that generates a PDF using some data that are send from user by POST. I created an action controller and PDF is being generated just fine. The problem is when I want to create a Response of "application/pdf" type in this controller the PDF is corrupted as it contains website HTML. I tried several things like returning the pdf by stream or saving the file and pointing to it using FilePathResult. I cleared Response before transmitting the file and close / end it after that but it keeps showing corrupted PDFs. The problem disappears when I place the action handler in PageController instead of BlockController. Do you know a way to fix this issue?

Regards,

Konrad

#139258
Sep 28, 2015 16:07
Vote:
 

If i understand the question correctly, in theory this should work

public class PDFBlockController : BlockControllerBase<PDFBlock>
    {

public override ActionResult Index(PDFBlock currentContent)
        {
YourBlockViewModel model = new YourBlockViewModel();
model.PDFFile = new File(//Prepare file)
return model;
}

}

View .cshtml
<embed src="model.PDFFile" type="application/pdf" />


Are you doing something differently?

Regards

/K

#139262
Edited, Sep 28, 2015 17:58
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.