📄 _myModal.cshtml Documentation

Path: IrbyImaging/Views/Imaging/_myModal.cshtml


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model: DocumentImaging
  4. Key Functional Areas
  5. API Endpoints Overview
  6. Third‐Party Integrations
  7. Sample Code Blocks
  8. UML Diagrams
  9. Usage Examples
  10. Conclusion

🔍 Overview & Purpose

_myModal.cshtml is a partial Razor view used in the IrbyImaging application. It renders a Bootstrap modal dialog to display details of a document, either as an embedded PDF preview or as OCR‑extracted text.

  • When to use?

    • Display details after a user selects a document from a list.
    • Provide both visual preview (if a PDF/image) or textual content (via OCR).
  • Key Responsibilities:

    1. Dynamically switch between preview mode and text mode based on Model.Preview.
    2. Show important metadata (Document Type & Category).
    3. Embed a PDF viewer or show OCR result.

🛠 Dependencies & Technologies

Technology Version / Notes
ASP.NET Core MVC Razor Pages / MVC views
Bootstrap 5 Modal component (data-bs- attributes)
C# / Razor Syntax @model, @if, @Html.DisplayFor, @Url.Action
PDF Embed Standard <embed> tag with PDF viewer
OCR Engine (Backend) Generates ImageOCRText

🗂 View Model: DocumentImaging

This partial view is strongly typed to the DocumentImaging model:

namespace IrbyImaging.Models
{
    public class DocumentImaging
    {
        public int DocumentImageId { get; set; }
        public bool Preview { get; set; }            // true = show PDF preview, false = show OCR text
        public string DocumentType { get; set; }
        public string DocumentCategory { get; set; }
        public string ImageOCRText { get; set; }     // result of OCR
    }
}
Property Type Description
DocumentImageId int Unique identifier for the document image.
Preview bool Flag to choose between PDF preview or OCR text display.
DocumentType string Type of document (e.g., Invoice, Report).
DocumentCategory string Category classification (e.g., Financial, Legal).
ImageOCRText string Raw text returned from OCR process.

🔑 Key Functional Areas

4.1 Header Section

<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: Statically set to “Document Details”.
  • Close Button: Uses Bootstrap’s btn-close to dismiss modal.

4.2 Body Section (Preview vs. OCR)

The body switches based on the Model.Preview boolean.

4.2.1 PDF Preview Mode (🔍 Preview = true)

@if (Model.Preview) {
  <div style="height: 600px">
    <div class="modal-body" style="height: 100%;">
      <p class="mb-2">
        Document Type: 
        <span class="text-primary">@Html.DisplayFor(m => m.DocumentType)</span>
      </p>
      <p class="mb-4">
        Document Category: 
        <span class="text-primary">@Html.DisplayFor(m => m.DocumentCategory)</span>
      </p>
      <embed height="100%" width="100%"
             src="@Url.Action("RenderImage", "Imaging",
                             new { id = Model.DocumentImageId, preview = true })
             #zoom=FitH"
             type="application/pdf">
    </div>
  </div>
}
  • Metadata Display
    • Uses @Html.DisplayFor to safely render DocumentType & DocumentCategory.
  • Embed PDF
    • Calls ImagingController.RenderImage(int id, bool preview) to stream the PDF.
    • Anchor #zoom=FitH instructs the PDF viewer to fit width horizontally.

4.2.2 OCR Text Mode (🔤 Preview = false)

@if (!Model.Preview) {
  <div class="modal-body">
    <p class="mb-2">
      Document Type:
      <span class="text-primary">@Html.DisplayFor(m => m.DocumentType)</span>
    </p>
    <p class="mb-4">
      Document Category:
      <span class="text-primary">@Html.DisplayFor(m => m.DocumentCategory)</span>
    </p>
    <div class="table-responsive">
      <span style="white-space: pre-wrap">@Model.ImageOCRText</span>
    </div>
  </div>
}
  • OCR Text
    • Wrapped in <span> with white-space: pre-wrap to preserve line breaks.
    • Allows long text to scroll within table-responsive container.

<div class="modal-footer">
  <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
  • Single Close button to dismiss the modal.
  • (Optional print button is commented out.)

🌐 API Endpoints Overview

Action Method Controller Route Purpose
RenderImage Imaging /Imaging/RenderImage?id={id}&preview=true Streams the requested document image/PDF for preview.
// Example signature in ImagingController
public IActionResult RenderImage(int id, bool preview) {
    // Retrieves binary PDF from storage
    // Returns File(stream, "application/pdf");
}

🔌 Third‐Party Integrations

  • Bootstrap 5
    • Modal, responsive utilities, buttons.
  • PDF Viewer
    • Utilizes browser plugin or built‑in PDF viewer via <embed>.
  • OCR Engine (Backend)
    • Converts image content to Model.ImageOCRText.

💻 Sample Code Blocks

Including the Partial View

@* In any parent view (e.g., Index.cshtml) *@
<button type="button"
        class="btn btn-primary"
        data-bs-toggle="modal"
        data-bs-target="#myDocumentModal"
        data-ajax-url="@Url.Action("GetDocumentModal", "Imaging", new { id = doc.Id })">
  View Details
</button>

<div class="modal fade" id="myDocumentModal" tabindex="-1" aria-hidden="true">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
      @* This will be replaced via AJAX *@
    </div>
  </div>
</div>

AJAX Load (jQuery)

$('#myDocumentModal').on('show.bs.modal', function (e) {
  var button = $(e.relatedTarget);
  var url = button.data('ajax-url');
  $(this).find('.modal-content')
         .load(url);
});

📐 UML Diagrams

classDiagram
    class DocumentImaging {
        +int DocumentImageId
        +bool Preview
        +string DocumentType
        +string DocumentCategory
        +string ImageOCRText
    }

    class ImagingController {
        +IActionResult RenderImage(int id, bool preview)
        +PartialViewResult GetDocumentModal(int id)
    }

    DocumentImaging <|-- _myModal.cshtml : Bind Model
    ImagingController --> _myModal.cshtml : returns PartialView

🧪 Usage Examples

  1. User clicks “View Details” on a document list.
  2. AJAX call to Imaging/GetDocumentModal?id=123.
  3. Controller populates DocumentImaging model:
    var model = new DocumentImaging {
      DocumentImageId = 123,
      Preview = true, // or false
      DocumentType = "Invoice",
      DocumentCategory = "Accounts Payable",
      ImageOCRText = "...OCR text..."
    };
    return PartialView("_myModal", model);
    
  4. Modal displays metadata + PDF or OCR text.
  5. Close button returns control to parent view.

🎯 Conclusion

The _myModal.cshtml partial view provides a flexible, reusable modal component for displaying document details in two modes:

  • Preview Mode (embedded PDF)
  • Text Mode (OCR output)

It leverages Bootstrap 5 for responsive UI and Razor for server‑side model binding. This pattern can be extended with print, download, or annotation features by uncommenting or adding new buttons in the footer.

🚀 Use this modular setup to enhance user experience when interacting with scanned documents or PDFs in the IrbyImaging application!