📄 deleteModal.cshtml Documentation
File Path:
IrbyImaging/Views/AccountingImaging/deleteModal.cshtml
Purpose: Display a Bootstrap modal that previews a PDF document and offers Print and Close actions before a delete operation.
🗂 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Model
- Key Functional Areas
4.1 Modal Container
4.2 Modal Header
4.3 Modal Body (PDF Preview)
4.4 Modal Footer (Actions) - How It Works (Flow)
- API Endpoint Overview
- Sample Usage
- UML Sequence Diagram
- Best Practices & Enhancements
- Conclusion
1. Overview & Purpose
This Razor Partial View renders a Bootstrap 5 modal dialog to give end‑users a preview of a PDF document stored in the system. Typically shown just before a document deletion or other critical operation, it allows:
- A quick visual verification of the document.
- A Print option for offline review.
- An easy Close button to cancel/exit the preview.
🔑 Key Benefit: Reduces accidental deletions by confirming content via a live PDF embed.
2. Dependencies & Technologies
| Technology | Version/Details |
|---|---|
| ASP.NET Core MVC | Razor view engine |
| Bootstrap | v5 (uses modal, btn, data-bs- attributes) |
HTML5 <embed> |
PDF embedding with zoom control (#zoom=FitH) |
| jQuery (optional) | For AJAX/DOM triggers if loading via script |
| Controller Action | AccountingImagingController.RenderDeleteImagePrev(int id, bool preview) |
3. View Model
@model IrbyImaging.Models.DocumentImaging
Important Property:
| Property | Type | Description |
|---|---|---|
DocumentImageId |
int |
Unique identifier of the PDF to preview. |
🎯 Note: Only
DocumentImageIdis directly consumed in this view. OtherDocumentImagingproperties can be extended for metadata display (e.g., file name, date).
4. Key Functional Areas
4.1 Modal Container
<div class="modal-content" style="height: 100%;">
...
</div>
.modal-content: Root container for the Bootstrap modal.- Inline style
height: 100%used to stretch content vertically.
4.2 Modal Header
<div class="modal-header">
<h5 class="modal-title" id="transaction-detailModalLabel">Document Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
- Title: “Document Details” (can be localized).
- Close Button: Standard Bootstrap close icon.
4.3 Modal Body (PDF Preview)
<div style="height: 600px">
<div class="modal-body" style="height: 100%;">
<embed
height="100%" width="100%"
src="@Url.Action(
"RenderDeleteImagePrev",
"AccountingImaging",
new { id = Model.DocumentImageId, preview = true }
)#zoom=FitH"
type="application/pdf">
</div>
</div>
- Container Height: Fixed at
600px. <embed>Tag:src: Dynamically generated URL to the controller action.#zoom=FitH: Ensures the PDF fits horizontally.type="application/pdf": Browser PDF plug‑in mode.
4.4 Modal Footer (Actions)
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
Print Document
</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
Close
</button>
</div>
| Button Label | Classes | Action |
|---|---|---|
| Print Document | btn btn-secondary |
Currently dismisses modal (see enhancements) |
| Close | btn btn-secondary |
Dismisses modal |
5. How It Works (Flow)
-
Partial View Rendered
A parent view or controller action loadsdeleteModal.cshtmlwith aDocumentImagingmodel. -
Razor Processing
@modelbinds the view.@Url.Action("RenderDeleteImagePrev", …)constructs the PDF URL.
-
Modal Display
- The calling script triggers the modal (e.g., via
data-bs-toggle="modal"or JavaScript). - The
<embed>fetches the PDF stream from the server.
- The calling script triggers the modal (e.g., via
-
User Interaction
- Print: Intended to call
window.print()(enhancement needed). - Close: Hides the modal without action.
- Print: Intended to call
6. API Endpoint Overview
AccountingImagingController.RenderDeleteImagePrev
| HTTP Verb | Route | Parameters | Returns |
|---|---|---|---|
| GET | /AccountingImaging/RenderDeleteImagePrev |
int id, bool preview |
PDF stream (File) |
public IActionResult RenderDeleteImagePrev(int id, bool preview)
{
// 1. Load document bytes from database or storage
// 2. Optionally apply watermark if preview == true
// 3. return File(bytes, "application/pdf");
}
7. Sample Usage
7.1 Partial Load in Parent View
@* Somewhere in List or Details page *@
<button class="btn btn-danger"
data-bs-toggle="modal"
data-bs-target="#deleteModal"
data-id="@item.DocumentImageId">
Delete Preview
</button>
@* Placeholder for modal *@
<div class="modal fade" id="deleteModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
@* Will be replaced via AJAX or Partial *@
</div>
</div>
</div>
@section Scripts {
<script>
$('#deleteModal').on('show.bs.modal', function (e) {
var button = $(e.relatedTarget);
var id = button.data('id');
$(this).find('.modal-content').load(
'/AccountingImaging/DeleteModal?id=' + id
);
});
</script>
}
7.2 Direct Partial Rendering
// Controller
public IActionResult DeleteModal(int id)
{
var model = _documentService.GetDocumentById(id);
return PartialView("deleteModal", model);
}
8. UML Sequence Diagram
@startuml
actor User
participant Browser
participant "deleteModal.cshtml" as View
participant AccountingImagingController
User -> Browser: Click "Delete Preview" button
Browser -> View: Show Bootstrap Modal
View -> AccountingImagingController: GET RenderDeleteImagePrev(id, preview=true)
AccountingImagingController -> View: PDF File Stream
View -> Browser: Embed PDF via <embed> tag
User -> Browser: Click Print / Close
Browser -> Browser: Print (or Close modal)
@enduml
9. Best Practices & Enhancements
-
🔧 Print Button
- Currently only dismisses modal.
- Enhancement:
<button id="btnPrint" class="btn btn-secondary">Print Document</button> <script> $('#btnPrint').on('click', function() { document.querySelector('#deleteModal embed').focus(); window.print(); }); </script>
-
🔒 Security
- Ensure the
idparameter is authorized; avoid direct object reference vulnerabilities. - Sanitize inputs in
RenderDeleteImagePrev.
- Ensure the
-
♿ Accessibility
- Add
aria-labels to buttons. - Ensure focus trapping inside modal.
- Add
-
📐 Responsive Height
- Instead of a fixed
600px, considermax-height: 80vh;.
- Instead of a fixed
10. Conclusion
The deleteModal.cshtml partial view provides a user‑friendly, in‑browser PDF preview for document verification before deletion. Leveraging ASP.NET Core MVC, Razor, and Bootstrap 5, it combines server‑side PDF streaming with a clean UI. By following the above best practices, you can further improve usability, security, and maintainability.
🚀 Happy Coding!