Reputation: 1594
I apologize if this is a little vague, however the issue presenting itself isnt giving too much away. I have been writting an application that uses MigraDoc to generate PDFs. The controller method used to generate and download the PDF is as follows:
public FileContentResult ConvertToPDF(int reportTypeId, string cultureName, int headerFooterTemplateId, int baseClassId, string baseTypeName)
{
try
{
string resourcePath = @"C:\TFS\Products\EnGenero\Trunk\EnGenero Application\RiskNetResources\bin\Debug\RiskNetResources.dll"; // --<<-- Reference this
byte[] result = new DocumentWriter().ConvertDocumentToPDFSharp(GetSeedData(reportTypeId, cultureName, resourcePath, headerFooterTemplateId, baseClassId));
return new FileContentResult(result, "application/pdf")
{
FileDownloadName = "MyReportFile.pdf"
};
}
catch (Exception ex)
{
Logger.Instance.LogError("Error in ConvertToPDF", ex);
return new FileContentResult(GetBytes("Error fetching pdf, " + ex.Message + Environment.NewLine + ex.StackTrace), "text/plain");
}
}
During development this has worked fine and when the above code is hit the PDF downloads through the browser fine. During development I was calling this controller method directly from a JQuery dialog box with Hard Coded parameters.
However, I further developed the application and now call this action method through an Ajax Post in a partial view.
function CreateDocumentPDF() {
var baseClassId = @Html.Raw(Json.Encode(ViewData["baseClassId"]));
var baseTypeName = @Html.Raw(Json.Encode(ViewData["baseTypeName"]));
var reportTypeId = $j('#ddlReportType option:selected').attr('Value');
var branchId = $j('#ddlBranch option:selected').attr('Value');
var languageId = $j('#ddlLanguage option:selected').attr('Value');
$j.ajax({
url: appRoot + 'DocumentPDFPrinter/ConvertToPDF',
type: 'post',
data: { 'reportTypeId': reportTypeId, 'cultureName': languageId, 'headerFooterTemplateId': branchId, 'baseClassId': baseClassId, 'baseTypeName': baseTypeName },
success: function (data) {
closeDefaultPopup();
},
failure: function () {
alert("Error Generating PDF.");
}
});
}
The same exact same parameter values are passed and the controller action runs through as expected however now there is no file generated/downloaded.
I can only imagine it is something to do with the Ajax post as this is the only difference between it running fine or not from what I can see.
This is the response I am getting - looks okay as far as I can see...? Am I missing anything?
Upvotes: 0
Views: 641
Reputation: 1594
So I simply moved away from the AJAX call and instead am now calling:
window.location = appRoot + "DocumentPDFPrinter/ConvertToPDF?reportTypeId=" + reportTypeId + "&cultureName=" + languageId etc...
Which seems to do the job nicely.
Upvotes: 0