📄 Documentation: _myModalPreview.cshtml
Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Model & Data Model
- API Endpoint Overview
- Modal Structure Breakdown
- Sample Code Blocks & Usage Examples
- UML Sequence Diagram
- Error Handling & Edge Cases
- Third‑party Integrations
- Conclusion
1. Overview & Purpose
File: IrbyImaging/Views/HRImaging/_myModalPreview.cshtml
Component Type: Razor Partial View
Description:
This partial view renders a Bootstrap 5 modal dialog to preview a document (PDF) on the client side. It uses an <embed> element pointing to a controller action that streams the PDF for in-browser viewing.
Use Case:
- HR staff or end-users click a “Preview” button in the UI.
- The modal pops up with the embedded PDF.
- Users can print or close the document preview.
2. Key Functional Areas
| Section | Responsibility |
|---|---|
| Modal Header | Displays title & close button 🏷️ |
| Modal Body | Contains an <embed> for PDF display |
| Modal Footer | Offers Print Document and Close buttons |
@model Declaration |
Binds the view to DocumentImaging model |
Url.Action("RenderImagePrev", ...) |
Generates the PDF streaming URL |
3. Dependencies & Technologies
- ASP.NET MVC / Razor: View engine
- Bootstrap 5: Modal styling & behavior
- JavaScript (Bootstrap JS): Controls modal life-cycle
- Browser PDF Embed:
<embed type="application/pdf">for inline PDF - Tag Helpers:
data-bs-dismiss="modal"
4. View Model & Data Model
View Model
@model IrbyImaging.Models.DocumentImaging
DocumentImaging (simplified)
| Property | Type | Description |
|---|---|---|
| TempDocumentId | Guid/int | Unique identifier for the temporary PDF |
| FileName | string | Original file name (optional) |
| MIMEType | string | e.g., "application/pdf" |
| CreatedDate | DateTime | Timestamp of upload |
Note: Only
TempDocumentIdis used in this view. The rest may be used elsewhere.
5. API Endpoint Overview
| Controller | Action | HTTP Method | Route | Returns |
|---|---|---|---|---|
| HRImagingCtrl | RenderImagePrev | GET | /HRImaging/RenderImagePrev?id={id}&preview=true |
PDF stream (FileResult) |
Signature (example):
public ActionResult RenderImagePrev(Guid id, bool preview = false)
{
var doc = _repository.GetTempDocument(id);
return File(doc.Content, "application/pdf");
}
6. Modal Structure Breakdown
<div class="modal-content" style="height: 100%;">
<!-- Header -->
<div class="modal-header">
<h5 class="modal-title">Document Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<!-- Body -->
<div style="height: 600px">
<div class="modal-body" style="height: 100%;">
<embed
width="100%"
height="100%"
src="@Url.Action("RenderImagePrev", "HRImaging", new { id = Model.TempDocumentId, preview = true })#zoom=FitH"
type="application/pdf">
</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-header: Title & close icon.modal-body: Fixed height container for PDF embed.modal-footer: Action buttons
7. Sample Code Blocks & Usage Examples
7.1 Rendering the Partial in a Parent View
@model IrbyImaging.Models.DocumentImaging
<!-- Trigger Button -->
<button
class="btn btn-primary"
data-bs-toggle="modal"
data-bs-target="#docPreviewModal">
Preview PDF
</button>
<!-- Modal Container -->
<div class="modal fade" id="docPreviewModal" tabindex="-1">
<div class="modal-dialog modal-xl">
@Html.Partial("_myModalPreview", Model)
</div>
</div>
7.2 Example Controller Action
public class HRImagingController : Controller
{
// GET: HRImaging/RenderImagePrev
public IActionResult RenderImagePrev(Guid id, bool preview = true)
{
var document = _repo.GetTemporaryDocument(id);
if (document == null)
return NotFound();
return File(document.Content, document.MIMEType);
}
}
8. UML Sequence Diagram
User
│
▼ Click “Preview PDF”
Parent View (JS + Bootstrap)
│ data-bs-toggle="modal"
▼
Modal Partial (_myModalPreview.cshtml)
│ HTML + <embed src="/HRImaging/RenderImagePrev?…">
▼
HRImagingController.RenderImagePrev()
│ Fetch PDF
▼
Browser
│ Renders PDF in embed frame
▼
User sees preview 👍
9. Error Handling & Edge Cases
| Scenario | Behavior | Recommendation |
|---|---|---|
Invalid TempDocumentId |
Controller returns 404 Not Found → embed shows error icon |
Show friendly message in modal-body |
| PDF fails to load | Blank embed or browser-specific PDF error | Fallback: display link to download file |
| User clicks “Print” | Currently dismisses modal (no print) | Attach onclick="window.print()" |
10. Third‑party Integrations
- Bootstrap 5 (CSS & JS)
- Native browser PDF rendering (Chrome, Edge, Firefox)
11. Conclusion
This Razor partial _myModalPreview.cshtml provides an out-of-the-box Bootstrap modal to preview PDF documents dynamically. By leveraging the DocumentImaging model and the RenderImagePrev controller action, it seamlessly streams PDF content directly into the UI.
🔧 Next Steps / Customization
- Add proper error messages when the PDF fails to load.
- Wire up the Print Document button to call
window.print()before dismissal. - Extend footer with Download link using
Url.Action("Download", ...).
Happy coding! 🎉