š DocPreview.cshtml Documentation
Welcome to the in-depth documentation for IrbyImaging/Views/Imaging/DocPreview.cshtml. This Razor view powers the āIndex Documentsā page, allowing users to preview, select, index, and delete uploaded PDF documents within the Imaging area of the application.
š Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Models & Data Models
- API Endpoints Overview
- Detailed Code Walkthrough
- Helper Methods & Utilities
- Thirdāparty Integrations
- Usage Examples & Code Snippets
- Error Handling & Return Types
- Conclusion
1. Overview & Purpose
š DocPreview.cshtml is a Razor View that:
- Previews uploaded PDF documents in a grid layout.
- Allows selecting single or multiple documents via checkboxes.
- Provides āSelect Allā functionality.
- Supports indexing (i.e., saving metadata) for selected documents.
- Enables deletion of selected documents.
- Offers a modal preview for a closer look at each PDF.
- Handles both multi-page and single-page upload scenarios.
This page is part of the Imaging module and works in tandem with the ImagingController actions:
SaveDocument (POST)Preview (GET)myModalPreview (GET)DocumentPreview (GET)
2. Key Functional Areas
| Area | Description |
|---|---|
| š Model Binding | Binds to IrbyImaging.Models.DocumentImaging to access BatchIds, SinglePageUpload, etc. |
| š Preview Display | Uses <embed> tags and AJAXāpowered modal for PDF preview. |
| ā Selection & Bulk Actions | Checkboxes, āSelect Allā toggle, Submit buttons for indexing or deleting docs. |
| šļø Multiāpage vs. Singleāpage | Conditional rendering based on BatchIds.Count and SinglePageUpload. |
| šļø Metadata Capture | When uploading a single page, presents a form to collect document metadata. |
| š ļø Helper Scripts | JavaScript functions for confirmation dialogs, AJAX calls, and checkbox toggling. |
3. Dependencies & Technologies
| Category | Libraries / Frameworks |
|---|---|
| UI Framework | ASP.NET MVC Razor, Bootstrap 5 |
| JavaScript & Plugins | jQuery, Bootstrap Bundle, MetisMenu, SimpleBar, Waves.js, Bootstrap Datepicker |
| WYSIWYG Editor | TinyMCE |
| File Upload Support | Dropzone (CSS included) |
| Styling | Custom CSS for flex layouts, Bootstrap classes |
4. View Models & Data Models
4.1. DocumentImaging Model (Simplified)
+---------------------------+
| DocumentImaging |
+---------------------------+
| Guid DocumentImageId |
| List<Guid> BatchIds |
| bool SinglePageUpload |
| bool DeleteFiles |
| string DocumentType |
| string JobNumber |
| string JobName |
| string JobOwner |
| string JobAddress |
| string UnitNumber |
| string AssignedToEmployeeId |
| string AssignedToEmployeeName |
| string WorkOrder |
| string CompletedBy |
| string JobDate |
| string DocumentNotes |
+---------------------------+
- BatchIds: IDs of uploaded documents pending indexing.
- SinglePageUpload: Flag for single-page vs. multi-page upload workflows.
- DeleteFiles: Hidden value set when the user confirms deletion.
5. API Endpoints Overview
| Action Method | HTTP Verb | Route | Purpose |
|---|---|---|---|
| Preview | GET | /Imaging/Preview?id={GUID} |
Returns PDF to embed in page or modal. |
| myModalPreview | GET | /Imaging/myModalPreview |
Returns partial view HTML for modal content. |
| SaveDocument | POST | /Imaging/SaveDocument |
Persists indexing selections/metadata. |
| DocumentPreview | GET | /Imaging/DocumentPreview |
Shows final saved document in an embed. |
6. Detailed Code Walkthrough
6.1 Initial Setup & Model Binding
@model IrbyImaging.Models.DocumentImaging
@{
ViewData["Title"] = "Save Uploaded Document";
Layout = "~/Views/Shared/_Layout.cshtml";
// Build comma-separated GUID list for metadata forms
var lists = new List<Guid>();
string guidList = "";
if (Model?.BatchIds != null) {
lists = Model.BatchIds;
foreach (var id in lists) { guidList += id + ","; }
}
}
- Model Declaration: Binds the page to
DocumentImaging. - Layout & Title: Uses the shared
_Layout.cshtmland sets a descriptive title. - Batch ID Enumeration: Prepares a
guidListstring for later hidden fields.
6.2 Styles & Scripts Sections
@section styles {
<!-- Datepicker & Dropzone CSS -->
<link href="~/assets/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet">
<link href="~/assets/libs/dropzone/min/dropzone.min.css" rel="stylesheet">
}
<style>
.flex-container { display: flex; flex-wrap: wrap; }
.flex-container > div { /* styling for demo */ }
</style>
- @section styles: Injects pageāspecific CSS dependencies.
- Inline CSS: Defines a simple flex layout (used in commented/demo code).
At the bottom of the file, the @section scripts block includes:
- jQuery, Bootstrap JavaScript, MetisMenu, SimpleBar, Waves
- Bootstrap Datepicker, TinyMCE
- Custom JS:
deleteFiles()Ā āĀ prompts user for confirmation.- Checkbox āSelect Allā toggler.
- AJAX preview loader for modals.
6.3 Document Indexing Forms (Multiāpage)
When BatchIds.Count > 1, the view renders:
-
Form:
@using (Html.BeginForm("SaveDocument","Imaging",FormMethod.Post,Model)) { @Html.HiddenFor(m=>m.DocumentImageId) @Html.HiddenFor(m=>m.BatchIds) <!-- Bulk actions toolbar --> <label>Select All</label> <input id="ckbCheckAll" type="checkbox" /> <button type="submit">Index Selected Documents</button> <button type="submit" onclick="deleteFiles();" class="btn btn-danger">Delete</button> ... } -
Document Grid:
- Loops through each
Model.BatchIds. - Uses
<embed src="@Url.Action("Preview","Imaging", new { id = docId })#zoom=FitH" type="application/pdf">to inline the PDF. - A checkbox (
name="docIds") to select each document. - A Preview link that triggers an AJAX call to
myModalPreview.
- Loops through each
-
Layout:
- Groups 4 documents per Bootstrap row (
.col-md-3). - Provides bottomāaligned Index button for convenience.
- Groups 4 documents per Bootstrap row (
6.4 Singleāpage Upload & Metadata Capture
When BatchIds.Count == 1 && SinglePageUpload == true, the interface switches to a metadata capture form:
- Dropdown:
DocumentType(pre-populated list of document categories). - Textareas:
JobNumber,JobName,JobOwner,JobAddress, etc. - Hidden:
batchIdcontaining the comma-separated GUID list. - Save Document button triggers
Saveaction viaSubmitForm()JavaScript (validation hook).
@using(Html.BeginForm("Save","Imaging",FormMethod.Post)) {
@Html.HiddenFor(m=>m.DocumentImageId)
@Html.Hidden("batchId", guidList)
<!-- Document Type select -->
<select asp-for="DocumentType">
<option>Select Type</option>
<option>ANNUAL CRANE INSPECT REP</option>
...
</select>
<!-- Metadata fields -->
<textarea asp-for="JobNumber" placeholder="Enter the Job Number..."></textarea>
...
<button type="submit" id="saveDocument" class="btn btn-primary">Save Document</button>
}
After saving metadata, the view continues to embed the processed PDF preview via:
<embed src="@Url.Action("DocumentPreview","Imaging", new { id = guidList })#zoom=FitH" type="application/pdf">
6.5 No Pending Documents Scenario
If Model.BatchIds.Count == 0, a friendly message is shown:
No Pending Documents are available to Index. Please upload documents to continue Indexing.
7. Helper Methods & Utilities
- deleteFiles()
function deleteFiles() { var r = confirm("Are you sure you want to delete the selected documents?"); if (!r) return false; $("#DeleteFiles").val("True"); } - Select All Toggle
$("#ckbCheckAll").click(function () { $(".checkBoxClass").prop('checked', $(this).prop('checked')); }); - AJAX Preview Modal
$(".previewDetail").click(function () { var id = $(this).data('id'); $.ajax({ type: "GET", url: '/Imaging/myModalPreview', data: { id: id, Preview: true }, success: function(html) { $('#myModalContent').html(html); $('#myModal').modal('show'); }, error: function() { alert("Failed to load preview."); } }); });
8. Thirdāparty Integrations
- Bootstrap Datepicker for date fields (if extended).
- Dropzone (CSS only in this view) ā ready for dragāandādrop uploads elsewhere.
- TinyMCE ā WYSIWYG support (scripts loaded but not currently used).
9. Usage Examples & Code Snippets
Example: Index Multiple PDFs
@model IrbyImaging.Models.DocumentImaging
<!-- Suppose Model.BatchIds has 5 GUIDs -->
@Html.BeginForm("SaveDocument","Imaging", FormMethod.Post) {
<input type="checkbox" id="ckbCheckAll"/> Select All
@foreach(var id in Model.BatchIds) {
<embed src="@Url.Action("Preview","Imaging", new { id = id })#zoom=FitH" type="application/pdf"/>
<input type="checkbox" name="docIds" value="@id"/>
}
<button type="submit">Index Selected</button>
<button onclick="deleteFiles()">Delete</button>
}
Example: SingleāPage Metadata Form
@using(Html.BeginForm("Save","Imaging", FormMethod.Post)) {
@Html.HiddenFor(m=>m.DocumentImageId)
<select asp-for="DocumentType">ā¦</select>
<textarea asp-for="JobNumber"></textarea>
<button type="submit">Save Document</button>
}
10. Error Handling & Return Types
- Clientāside:
confirm()for deletion.alert()on AJAX errors.
- Serverāside (ImagingController):
- Should validate
Model.BatchIdsand metadata fields. - Returns
PartialViewformyModalPreviewor redirects afterSaveDocument.
- Should validate
11. Conclusion
š DocPreview.cshtml is a dynamic, featureārich Razor view enabling:
- Flexible handling of batch vs. single document workflows.
- Inline PDF previews and detailed metadata capture.
- Bulk operations (indexing & deletion) with userāfriendly confirmations.
- AJAXāpowered modal popups for a seamless preview experience.
By combining ASP.NET MVC helpers, Bootstrap layouts, and custom JavaScript utilities, it provides a robust interface for indexing and managing document images within the Irby Imaging system.
Thank you for exploring the DocPreview.cshtml documentation! š If you have any further questions or need code samples, feel free to reach out.