π DocPreview.cshtml Documentation
File Path:
IrbyImaging/Views/AccountingImaging/DocPreview.cshtml
π Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Model:
DocumentImaging - Markup Breakdown
- JavaScript Helpers & Utilities
- API Endpoints & Ajax Usage
- Error Handling & User Feedback
- Mermaid UML Diagrams
- Usage Examples
- Conclusion & Recommendations
π Overview & Purpose
This Razor View enables end-users to:
- Preview uploaded PDF documents in a thumbnail grid.
- Select one or multiple documents for indexing or deletion.
- Submit the selected documents back to the
AccountingImagingControllerfor further processing.
Itβs intended for the Accounting Imaging workflow, where batches of scanned documents must be reviewed, indexed (tagged), or removed before final archival.
π― Key Functional Areas
| Area | Description |
|---|---|
| PDF Embedding | Renders each document as an <embed> PDF thumbnail with #zoom=FitH. |
| Selection Controls | Checkboxes and βSelect Allβ toggle to pick documents for actions. |
| Form Submission | Posts selected document IDs to SaveDocument action with category routing. |
| Deletion Confirmation | JavaScript confirm() dialog before marking files for deletion. |
| Asynchronous Preview Modal | AJAX call to load a full-size preview inside a Bootstrap modal window. |
π οΈ Dependencies & Technologies
- ASP.NET MVC (Razor view engine)
- jQuery for DOM manipulation & AJAX
- Bootstrap 4/5 for grid & modal styling
- Bootstrap Datepicker (CSS included; unused in this view)
- Dropzone.js (CSS included; reserved for file uploads elsewhere)
- TinyMCE, MetisMenu, Simplebar, Node-waves (global scripts)
π€ View Model: DocumentImaging
namespace IrbyImaging.Models
{
public class DocumentImaging
{
public Guid DocumentImageId { get; set; }
public List<Guid> BatchIds { get; set; }
public string ImagingType { get; set; }
public bool IsLegalDocument { get; set; }
public bool IsSafety { get; set; }
public bool IsIT { get; set; }
public bool IsAccounting { get; set; }
public bool IsBidding { get; set; }
public bool DeleteFiles { get; set; }
}
}
Key Properties
BatchIds: List of document GUIDs to displayDeleteFiles: Toggle set via JS for deletion
π Markup Breakdown
5.1 Form & Hidden Fields
@using (Html.BeginForm(
"SaveDocument",
"AccountingImaging",
new { category = ViewBag.category },
FormMethod.Post,
null,
Model))
{
@* Persist important model data *@
@Html.HiddenFor(m => m.DocumentImageId)
@Html.HiddenFor(m => m.BatchIds)
@Html.HiddenFor(m => m.ImagingType)
@Html.HiddenFor(m => m.IsLegalDocument)
@Html.HiddenFor(m => m.IsSafety)
@Html.HiddenFor(m => m.IsIT)
@Html.HiddenFor(m => m.IsAccounting)
@Html.HiddenFor(m => m.IsBidding)
@* DeleteFiles is set by JS *@
<input type="hidden" id="DeleteFiles" name="DeleteFiles" value="False" />
- Action:
AccountingImaging/SaveDocument - Route Value:
category(fromViewBag) - Hidden Inputs: Preserve model state between posts
5.2 PDF Thumbnail Grid
<div class="row">
@for (int k = 0; k < Model.BatchIds.Count; k++)
{
if (k > 0 && k % 4 == 0) { </div><br /><div class="row"> }
<div class="col-md-3">
<div class="thumbnail">
<embed
src="@Url.Action("Preview","AccountingImaging", new { id = Model.BatchIds[k] })#zoom=FitH"
type="application/pdf" />
<div class="preference">
<label>Select</label>
<input
type="checkbox"
class="checkBoxClass"
name="docIds"
value="@Model.BatchIds[k]" />
</div>
<a
href="javascript:void(0);"
class="previewDetail"
data-id="@Model.BatchIds[k]">
Preview π
</a>
<!-- Modal placeholder -->
<div id="myModal" class="modal">
<div class="modal-dialog">
<div class="modal-content">
<div id="myModalContent"></div>
</div>
</div>
</div>
</div>
</div>
}
</div>
- Grid Layout: 4 thumbnails per row (Bootstrap
col-md-3). - Embed: Inline PDF (
#zoom=FitHfits width). - Preview Link: Triggers AJAX-loaded modal.
5.3 Select All & Delete Controls
<div class="preference">
<label>Select All</label>
<input id="ckbCheckAll" type="checkbox" />
<div style="float:right;">
<input type="submit" class="btn btn-primary" value="Index Selected Documents" />
<button type="submit" class="btn btn-danger" onclick="deleteFiles();">Delete</button>
</div>
</div>
- #ckbCheckAll: Toggles
.checkBoxClass. - Index Button: Submits form for indexing.
- Delete Button: Calls
deleteFiles()JS before submit.
π» JavaScript Helpers & Utilities
// 1. Delete Confirmation
function deleteFiles() {
if (!confirm("Are you sure you want to delete the selected documents?"))
return false;
$("#DeleteFiles").val("True");
}
// 2. Select All Checkbox
$(document).ready(function () {
$("#ckbCheckAll").click(function () {
$(".checkBoxClass").prop('checked', $(this).prop('checked'));
});
});
// 3. AJAX Preview Modal
var TeamDetailPostBackURL = '/AccountingImaging/myModalPreview';
$(function () {
$(".previewDetail").click(function () {
var id = $(this).data('id');
$.ajax({
type: "GET",
url: TeamDetailPostBackURL,
data: { id: id, Preview: true },
success: function (data) {
$('#myModalContent').html(data);
$('#myModal').modal('show');
},
error: function () {
alert("Dynamic content load failed.");
}
});
});
});
deleteFiles(): Marks the hiddenDeleteFilesflag after confirmation.#ckbCheckAll: Bulk-selects checkboxes.- AJAX Preview: Loads partial view into modal without full page reload.
πͺ API Endpoints & AJAX Usage
| Endpoint | Verb | Parameters | Description |
|---|---|---|---|
/AccountingImaging/Preview?id={guid} |
GET | id (document GUID) |
Returns raw PDF stream for <embed>. |
/AccountingImaging/myModalPreview |
GET | id, Preview=true |
Returns HTML snippet for the modal body. |
/AccountingImaging/SaveDocument?category= |
POST | Form data (docIds[], flags) |
Processes indexing and deletion. |
β οΈ Error Handling & User Feedback
- Deletion Confirmation: Uses native
confirm(). - AJAX Errors: Pops up
alert("Dynamic content load failed."). - No Documents Case:
<h5>No Pending Documents are available to Index. Please upload documents to continue Indexing.</h5>
π Mermaid UML Diagrams
1. Sequence Diagram
sequenceDiagram
participant U as User
participant V as DocPreview.cshtml
participant C as AccountingImagingController
U->>V: Request DocPreview view
V->>C: Url.Action("Preview", id)
V->>C: AJAX GET myModalPreview
U->>V: Click "Index Selected Documents"
V->>C: POST SaveDocument(form)
2. Class Diagram
classDiagram
class DocumentImaging {
+Guid DocumentImageId
+List~Guid~ BatchIds
+string ImagingType
+bool IsLegalDocument
+bool IsSafety
+bool IsIT
+bool IsAccounting
+bool IsBidding
+bool DeleteFiles
}
π§ Usage Examples
// In AccountingImagingController.cs
public IActionResult DocPreview(Guid batchGroupId, string category)
{
var model = _imagingService.GetDocumentImaging(batchGroupId);
ViewBag.category = category;
return View("DocPreview", model);
}
<!-- Rendered in parent view or layout -->
<a href="@Url.Action("DocPreview","AccountingImaging", new { batchGroupId = someGuid, category = "Accounting" })">
Index Documents
</a>
π Conclusion & Recommendations
- DRY Improvement: The view repeats markup for single vs. multiple documents. Consider extracting a partial or TagHelper.
- Accessibility: Add
aria-labels, proper form labeling, and focus management in the modal. - Error UX: Replace
alert()with a styled Bootstrap toast or inline message. - Pagination / Virtualization: For large batches, consider server-side paging or infinite scroll.
Happy Coding! π