📄 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

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model
  4. Key Functional Areas
    4.1 Modal Container
    4.2 Modal Header
    4.3 Modal Body (PDF Preview)
    4.4 Modal Footer (Actions)
  5. How It Works (Flow)
  6. API Endpoint Overview
  7. Sample Usage
  8. UML Sequence Diagram
  9. Best Practices & Enhancements
  10. 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 DocumentImageId is directly consumed in this view. Other DocumentImaging properties 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.
<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)

  1. Partial View Rendered
    A parent view or controller action loads deleteModal.cshtml with a DocumentImaging model.

  2. Razor Processing

    • @model binds the view.
    • @Url.Action("RenderDeleteImagePrev", …) constructs the PDF URL.
  3. 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.
  4. User Interaction

    • Print: Intended to call window.print() (enhancement needed).
    • Close: Hides the modal without action.

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 id parameter is authorized; avoid direct object reference vulnerabilities.
    • Sanitize inputs in RenderDeleteImagePrev.
  • ♿ Accessibility

    • Add aria-labels to buttons.
    • Ensure focus trapping inside modal.
  • 📐 Responsive Height

    • Instead of a fixed 600px, consider max-height: 80vh;.

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!