πŸ“„ Documentation: _myModalPreview.cshtml


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Model & Data Flow
  4. Key Functional Areas
  5. API Endpoints Overview
  6. Usage Examples & Sample Code
  7. Sequence UML Diagram
  8. 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 AccountingImagingController to fetch the binary PDF stream.

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 RenderImagePrev action to fetch the PDF stream

Data Flow

  1. View Rendered
    The partial is invoked with an instance of DocumentImaging.
  2. Embed Source
    The <embed> tag’s src calls:
    @Url.Action(
      "RenderImagePrev",                    // Action Method
      "AccountingImaging",                  // Controller
      new { id = Model.TempDocumentId,
            preview = true }                // Query parameters
    )
    
  3. Controller Action
    • Locates the PDF using TempDocumentId
    • Streams binary data back to the browser
  4. Browser Display
    • Inline PDF rendered with #zoom=FitH (fit to width)

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! πŸŽ‰