この投稿に基づいて動作させました
ファイルを返すコントローラーアクションが必要です。
[HttpGet]
public async Task<ActionResult> Print(int? poId) {
if (poId == null) {
return Json(new { success = true, errorMessage = "Could not find purchase order!" }, JsonRequestBehavior.AllowGet);
}
try {
PurchaseOrderWork dal = new PurchaseOrderWork(db);
var db_po = await dal.GetAsyncPurchaseOrderById(poId.Value);
var viewModel = GetEntryViewModel(db_po);
var file = ControllerContext.GeneratePdf(viewModel, "_PrintOut");
ViewBag.ID = poId;
return File(file, "application/pdf");
}
catch (DataException ex) {
return Json(new { success = true, errorMessage = "Failed to extract purchase order!", errorDetails = ex.Message },JsonRequestBehavior.AllowGet);
}
}
次に、cshtmlでhtmlオブジェクトをモーダルに配置します。
<div class=" container row form-horizontal">
<div id="printModal" class="modal fade in" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg print-dialog">
<div class="modal-content print-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Report ID = @ViewBag.ID</h4>
</div>
<div class="modal-body">
<div id="detailAlert" class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span>Some Errors have occured!</span>
</div>
<div class="form-group">
<object id="pdfbox" style="width: 100%; height: 800px; overflow:hidden"
type="application/pdf" data="@Url.Action("Print", "PurchaseOrders", new { poId=10 })"></object></object>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn green-haze btn-outline pull-left">
<span><i class="fa fa-fw fa-save"></i></span> Save
</button>
<button type="button" data-dismiss="modal" class="btn dark btn-outline">Close</button>
</div>
</div>
</div>
</div>
最後にあなたに渡しurl
ますhtml object
:
function PrintOrder(poId) {
var url = '/PurchaseOrders/Print?poId=' + poId;
// $.get(url, function (data) {
$('#printModal').find('object').prop('data', url);
$('#printModal').modal('show');
// });
}
このコードを改善できるかどうかコメントしてください