From 8065c589bc7d0319fe7843c332d778169fb4b0fd Mon Sep 17 00:00:00 2001 From: OlgunR Date: Tue, 2 Jun 2026 15:21:11 +0200 Subject: [PATCH] Enhance file attachment viewing experience Replaced direct file links with a JavaScript-based viewer (`openAttachmentViewer`) and added a DevExtreme Popup (`attachment-viewer-popup`) for displaying attachments in a modal dialog. The viewer supports PDFs (via PDF.js), XML (with CodeMirror syntax highlighting), plain text, images, and provides a fallback for unsupported file types. Dynamically load CodeMirror for XML files and handle errors gracefully when loading file content. Added `onAttachmentPopupHiding` to clear popup content on close. Updated `ViewAttachmentModel` to return text/XML content directly for AJAX requests, improving frontend performance and enabling dynamic content loading. --- .../Pages/Invoices/Details.cshtml | 118 +++++++++++++++++- .../Pages/Invoices/ViewAttachment.cshtml.cs | 9 +- 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/DXApp.TemplateKitProject/Pages/Invoices/Details.cshtml b/DXApp.TemplateKitProject/Pages/Invoices/Details.cshtml index 5fe836e..912064c 100644 --- a/DXApp.TemplateKitProject/Pages/Invoices/Details.cshtml +++ b/DXApp.TemplateKitProject/Pages/Invoices/Details.cshtml @@ -75,9 +75,9 @@ else _ => "📎" }; - + onclick="openAttachmentViewer('@attachment.OriginalFileName', '@Uri.EscapeDataString(attachment.SavedFilePath)', '@extension')">
@icon @attachment.OriginalFileName @@ -115,6 +115,20 @@ else return ''; }")) ) + +@(Html.DevExtreme().Popup() + .ID("attachment-viewer-popup") + .Title("Anhang") + .Width("90%") + .Height("90%") + .ShowCloseButton(true) + .OnHiding("onAttachmentPopupHiding") + .Shading(true) + .ShadingColor("rgba(0, 0, 0, 0.5)") + .ContentTemplate(new JS(@"function() { + return '
'; + }")) +) }