I am attempting to use an AJAX Post to download a PDF file and return the templateFile Model. However, I am encountering an error where it cannot convert type TemplateFileDto to IhttpActionResult. Should I consider returning something different? Any assistance would be greatly appreciated.
printItems(versionKeys: string[]): JQueryPromise<any> {
console.log('printItems');
$.ajax({
type: "post",
contentType: "application/json",
data: JSON.stringify(versionKeys),
url: this.apiUrls.PrintTemplates,
success: function (data, status, xhr) {
var file = new Blob([data], { type:' application/pdf' });
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
console.log('success');
}
});
return;
}
Controller
[HttpGet, HttpPost]
[ApplicationApiAuthorize("Administrator, ContentManager")]
public IHttpActionResult PrintTemplates([FromBody] List<string> versionKeys)
{
var templates = versionKeys
.Select(v => TemplatesDataService.GetTemplate(v))
.ToList();
var templateIds = templates.Select(b => b.Id).ToList();
var templateFile = TemplatesDataService.PrintTemplate(templateIds);
return templateFile;
}
Model
public class TemplateFileDto
{
public long? Id { get; set; }
public byte[] Content { get; set; }
public string FileName { get; set; }
public string ContentType { get; set; }
}