📄 _myModalPreview.cshtml Documentation
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Model & Data Model
- Key Functional Areas
- Bootstrap Modal Structure
- Razor Syntax & Helpers
- Controller Integration & API Endpoint
- Sample Usage & Code Snippets
- UML Diagrams
- Conclusion
🔍 1. Overview & Purpose
_myModalPreview.cshtml is a Razor partial view used to present a PDF document preview inside a Bootstrap modal dialog.
It’s part of the IrbyImaging web application within the LegalImaging area and expects a DocumentImaging model to generate an embedded PDF.
Use Cases
- Preview scanned or generated legal documents before printing
- Offer an in-browser PDF viewer with zoom-to-fit functionality
🛠 2. Dependencies & Technologies
| Technology | Version / Details |
|---|---|
| ASP.NET Core MVC | Razor Views |
| Bootstrap | v5.x (Modal & Buttons) |
| JavaScript | data-bs-* attributes for modal behaviour |
| C# Model Binding | @model IrbyImaging.Models.DocumentImaging |
| PDF Embedding | <embed> element for inline PDF rendering |
📦 3. View Model & Data Model
namespace IrbyImaging.Models
{
public class DocumentImaging
{
public Guid TempDocumentId { get; set; }
// ... other document-related properties
}
}
| Property | Type | Description |
|---|---|---|
TempDocumentId |
Guid |
Identifier of the temporary PDF to render |
🎯 4. Key Functional Areas
-
Modal Header
- Title: Document Details
- Close button (×)
-
Modal Body
<embed>PDF viewer set towidth="100%"/height="100%"- Uses
@Url.Action("RenderImagePrev", "LegalImaging", new { id = Model.TempDocumentId, preview = true })#zoom=FitH
-
Modal Footer
- Print Document button
- Close button
🧱 5. Bootstrap Modal Structure
<div class="modal-content" style="height: 100%;">
<!-- 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>
<!-- Body (Embedded PDF) -->
<div style="height: 600px">
<div class="modal-body" style="height: 100%;">
<embed
src="@Url.Action("RenderImagePrev","LegalImaging",
new { id = Model.TempDocumentId, preview = true })#zoom=FitH"
type="application/pdf"
width="100%" height="100%" />
</div>
</div>
<!-- Footer -->
<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>
</div>
- modal-content: Wrapper
- modal-header: Title & close
- modal-body: Embeds the PDF
- modal-footer: Action buttons
📜 6. Razor Syntax & Helpers
@model IrbyImaging.Models.DocumentImaging: Strongly‐typed view@Url.Action(...): Generates the URL for the PDF rendering endpoint
@model IrbyImaging.Models.DocumentImaging
<embed
src="@Url.Action("RenderImagePrev","LegalImaging",
new { id = Model.TempDocumentId, preview = true })#zoom=FitH"
/>
Note:
#zoom=FitHtells the browser plugin to fit the PDF horizontally.
🔗 7. Controller Integration & API Endpoint
LegalImagingController
public class LegalImagingController : Controller
{
// Returns PDF file stream for preview or download
public IActionResult RenderImagePrev(Guid id, bool preview = false)
{
var memStream = _documentService.GetDocumentStream(id);
var contentType = "application/pdf";
return new FileStreamResult(memStream, contentType);
}
}
| Parameter | Type | Description |
|---|---|---|
id |
Guid |
The document identifier |
preview |
bool |
True if in‐browser preview; otherwise download |
🔧 8. Sample Usage & Code Snippets
Invoking the Modal from Another View
<button
type="button"
class="btn btn-primary"
data-bs-toggle="modal"
data-bs-target="#myPreviewModal"
data-id="@Model.TempDocumentId">
Preview Document 📄
</button>
<div class="modal fade" id="myPreviewModal" tabindex="-1">
<div class="modal-dialog modal-xl" style="max-width: 90%;">
<div class="modal-content">
@await Html.PartialAsync("LegalImaging/_myModalPreview", Model)
</div>
</div>
</div>
JavaScript Hook (Optional)
// Re‐initialize embed on modal show if dynamic
$('#myPreviewModal').on('show.bs.modal', function (e) {
var btn = $(e.relatedTarget);
var docId = btn.data('id');
$(this).find('embed').attr('src',
`/LegalImaging/RenderImagePrev?id=${docId}&preview=true#zoom=FitH`);
});
📊 9. UML Diagrams
Class Diagram
classDiagram
DocumentImagingController <|-- _myModalPreview
DocumentImagingController : +RenderImagePrev(Guid id, bool preview)
DocumentImaging : TempDocumentId : Guid
_myModalPreview : @model DocumentImaging
_myModalPreview : uses embed src=Url.Action(...)
Sequence Diagram
sequenceDiagram
participant User
participant Browser
participant _myModalPreview
participant Controller
User->>Browser: Click "Preview Document"
Browser->>_myModalPreview: Show modal UI
_myModalPreview->>Controller: GET RenderImagePrev(id, preview=true)
Controller->>_myModalPreview: PDF Stream (FileStreamResult)
_myModalPreview->>Browser: Embed PDF viewer
Browser->>User: Display PDF
🏁 10. Conclusion
The _myModalPreview.cshtml partial view provides a seamless, in‐browser PDF preview of legal documents. By combining ASP.NET Core MVC, Razor, and Bootstrap 5, it:
- Renders a server‐generated PDF stream
- Displays it via an
<embed>for inline viewing - Supports zoom‐to‐fit and print/close actions
Use this view anywhere you need a quick, elegant document preview in your LegalImaging workflows! Enjoy your smooth PDF previews! ✨