How to Control File Downloads in ASP.NET MVC PDF Viewer
17 Aug 20261 minute to read
Use the downloadStart event to intercept the start of a download and optionally cancel it. In the event handler, set args.cancel = true to prevent the download.
By default, args.cancel is false, so the download proceeds unless explicitly canceled.
Flexibility
Leverage the downloadStart event to apply custom rules for allowing or preventing downloads based on application needs.
@{
ViewBag.Title = "Home Page";
}
<div style="width:100%;height:600px">
@Html.EJS().PdfViewer("pdfviewer").DocumentPath("https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf").DownloadStart("downloadStart").Render()
</div>
<script>
function downloadStart(args) {
// Your custom logic here
args.cancel = true; // Prevent download action
};
</script>@{
ViewBag.Title = "Home Page";
}
<div style="width:100%;height:600px">
@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(VirtualPathUtility.ToAbsolute("~/api/PdfViewer/")).DocumentPath("https://cdn.syncfusion.com/content/pdf/hive-succinctly.pdf").DownloadStart("downloadStart").Render()
</div>
<script>
function downloadStart(args) {
// Your custom logic here
args.cancel = true; // Prevent download action
};
</script>