π Documentation: _myModalPreview.cshtml
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Model & Data Flow
- Key Functional Areas
- API Endpoints Overview
- Usage Examples & Sample Code
- Sequence UML Diagram
- Conclusion
1. Overview & Purpose
This Razor view partial renders a Bootstrap modal that displays a PDFβbased document preview within the AccountingImaging section of the application.
- Filename:
IrbyImaging/Views/AccountingImaging/_myModalPreview.cshtml - Primary Goal: Show users a preview of a document (PDF) in a modal popup and give them options to print or close the preview.
- Usage Context:
- Called from a parent view (e.g., a list of scanned documents) via
@Html.Partial("_myModalPreview", model)or loaded dynamically via AJAX. - Integrates with the
AccountingImagingControllerto fetch the binary PDF stream.
- Called from a parent view (e.g., a list of scanned documents) via
2. Dependencies & Technologies
| Category | Details |
|---|---|
| Framework | ASP.NET MVC / Razor Views |
| Styling & Layout | Bootstrap 5 (modal, buttons, responsive embed) |
| PDF Rendering | <embed> tag for inline PDF display |
| URL Helper | @Url.Action() to generate the endpoint for PDF streaming |
| Model Namespace | IrbyImaging.Models.DocumentImaging |
π Third-Party Integrations
- Bootstrap 5: for modal markup and utilities
- Browserβs built-in PDF viewer: via the HTML
<embed>element
3. Model & Data Flow
DocumentImaging Model (Input)
namespace IrbyImaging.Models
{
public class DocumentImaging
{
public Guid TempDocumentId { get; set; }
// ... other metadata fields, e.g. Filename, CreatedDate, etc.
}
}
Model.TempDocumentId- Used to identify the document on the server
- Passed to the
RenderImagePrevaction to fetch the PDF stream
Data Flow
- View Rendered
The partial is invoked with an instance ofDocumentImaging. - Embed Source
The<embed>tagβssrccalls:@Url.Action( "RenderImagePrev", // Action Method "AccountingImaging", // Controller new { id = Model.TempDocumentId, preview = true } // Query parameters ) - Controller Action
- Locates the PDF using
TempDocumentId - Streams binary data back to the browser
- Locates the PDF using
- Browser Display
- Inline PDF rendered with
#zoom=FitH(fit to width)
- Inline PDF rendered with
4. Key Functional Areas
| Section | Description |
|---|---|
| Modal Container | <div class="modal-content"> β houses header, body, footer |
| Header | Shows title βDocument Detailsβ & close button (Γ) |
| Body | <embed> PDF viewer styled to fill height & width |
| Footer Buttons | - Print Document (currently only closes modal) |
| - Close |
Highlighted Snippet
<embed
height="100%"
width="100%"
src="@Url.Action("RenderImagePrev", "AccountingImaging",
new { id = Model.TempDocumentId, preview = true })#zoom=FitH"
type="application/pdf">
5. API Endpoints Overview
| Endpoint | Method | Purpose |
|---|---|---|
| /AccountingImaging/RenderImagePrev | GET | Streams the PDF content for a given id. |
Sample Controller Signature
public class AccountingImagingController : Controller
{
[HttpGet]
public IActionResult RenderImagePrev(Guid id, bool preview = false)
{
// 1. Lookup PDF by id
// 2. Return File(stream, "application/pdf");
}
}
6. Usage Examples & Sample Code
Including the Partial in a View
@model IrbyImaging.Models.DocumentImaging
<button
class="btn btn-primary"
data-bs-toggle="modal"
data-bs-target="#myModalPreview">
π Preview Document
</button>
<!-- Modal -->
<div class="modal fade" id="myModalPreview" tabindex="-1" aria-hidden="true">
@Html.Partial("_myModalPreview", Model)
</div>
Triggering via AJAX
$('.preview-btn').on('click', function() {
var docId = $(this).data('doc-id');
$.get('/AccountingImaging/LoadModalPreview', { id: docId })
.done(function(html) {
$('#myModalPlaceholder').html(html);
var modal = new bootstrap.Modal($('#myModalPreview'));
modal.show();
});
});
7. Sequence UML Diagram
[User]
β clicks βPreviewββββββββββββββββββββββββββ
β β
βΌ β
[Browser] [Server]
β GET /AccountingImaging/LoadModalPreview β
βββββββββββββββββββββββββββββββββββββββββ>β
β β
β Returns _myModalPreview.cshtml β
β<βββββββββββββββββββββββββββββββββββββββββ€
β β
β GET RenderImagePrev?id=... β
βββββββββββββββββββββββββββββββββββββββββ>β
β β
β 200 + PDF Stream (#zoom=FitH) β
β<βββββββββββββββββββββββββββββββββββββββββ€
β β
[Browser displays PDF in modal] β
8. Conclusion
This _myModalPreview.cshtml partial is a lightweight, reusable Razor component that:
- π Previews any PDF document inline
- π Integrates seamlessly with the
AccountingImagingController - π¨ Leverages Bootstrap 5 for a responsive, userβfriendly modal
By following the patterns outlined above, you can:
- Extend it to handle image previews
- Add more footer actions (e.g., download, annotate)
- Wire up clientβside printing (
window.print()) for the βPrint Documentβ button
Enjoy building rich documentβcentric UIs with this modular modal preview! π