📄 _myModal.cshtml Documentation
Path:
IrbyImaging/Views/Imaging/_myModal.cshtml
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Model:
DocumentImaging - Key Functional Areas
- API Endpoints Overview
- Third‐Party Integrations
- Sample Code Blocks
- UML Diagrams
- Usage Examples
- 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:
- Dynamically switch between preview mode and text mode based on
Model.Preview. - Show important metadata (Document Type & Category).
- Embed a PDF viewer or show OCR result.
- Dynamically switch between preview mode and text mode based on
🛠 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-closeto 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.DisplayForto safely renderDocumentType&DocumentCategory.
- Uses
- Embed PDF
- Calls
ImagingController.RenderImage(int id, bool preview)to stream the PDF. - Anchor
#zoom=FitHinstructs the PDF viewer to fit width horizontally.
- Calls
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>withwhite-space: pre-wrapto preserve line breaks. - Allows long text to scroll within
table-responsivecontainer.
- Wrapped in
4.3 Footer Section
<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>.
- Utilizes browser plugin or built‑in PDF viewer via
- OCR Engine (Backend)
- Converts image content to
Model.ImageOCRText.
- Converts image content to
💻 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
- User clicks “View Details” on a document list.
- AJAX call to
Imaging/GetDocumentModal?id=123. - Controller populates
DocumentImagingmodel:var model = new DocumentImaging { DocumentImageId = 123, Preview = true, // or false DocumentType = "Invoice", DocumentCategory = "Accounts Payable", ImageOCRText = "...OCR text..." }; return PartialView("_myModal", model); - Modal displays metadata + PDF or OCR text.
- 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!