📄 DeleteUploadedDocument.cshtml Documentation
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- ViewModel & Data Models
- Hidden Fields & Form Elements
- Sample Code Snippets
- Usage Example
- UML & Sequence Diagrams 📊
- Conclusion
1. Overview & Purpose
The DeleteUploadedDocument.cshtml Razor view provides a user interface for:
- Displaying a grid of previously uploaded documents (PDFs).
- Allowing users to select (via checkboxes) one or more documents.
- Providing an embedded preview of each document.
- Offering a modal preview for a full-screen look.
- Submitting a delete request to remove selected documents.
This view belongs to the HRImaging area and leverages the DocumentImaging model to orchestrate document IDs, preview flags, and deletion flags.
2. Dependencies & Technologies
| Category | Library / Component |
|---|---|
| Framework | ASP.NET Core MVC (Razor Views) |
| Front‑end Libraries | Bootstrap 4.x (CSS & JS), jQuery |
| Datepicker & Dropzone | bootstrap-datepicker, dropzone.js |
| UI Enhancements | metismenu, simplebar, node-waves, TinyMCE (unused) |
| Modal & AJAX | jQuery AJAX, Bootstrap Modals |
Note: Some scripts (TinyMCE, form repeater) are referenced but not actively used in this view.
3. Key Functional Areas
3.1 Model Binding 📝
@model IrbyImaging.Models.DocumentImaging
DocumentImagingcontains:Guid DocumentImageId– Main document identifier.List<Guid> BatchIds– IDs of all uploaded documents.bool DeleteFiles– Flag indicating deletion submission.
A quick pre-processing builds a comma‑separated string of all BatchIds (unused in final markup but illustrative of batch logic).
3.2 Layout & Styling 🎨
@{
ViewData["Title"] = "Delete Uploaded Document";
Layout = "~/Views/Shared/_Layout.cshtml";
}
- Title is set for the page header.
- Inherits site‑wide layout:
_Layout.cshtml. - Inline CSS for a simple flex container (unused in final grid).
Styles Section:
@section styles{
<link href="~/assets/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet">
<link href="~/assets/libs/dropzone/min/dropzone.min.css" rel="stylesheet" />
}
3.3 Document Rendering & Selection 📄
Documents are displayed in a responsive grid, 4 per row:
<div class="row">
@for (int k = 0; k < Model.BatchIds.Count; k++) {
if (counter != 0 && counter % 4 == 0) {
</div><br /><div class="row">
}
<div class="col-md-3">
<div class="thumbnail">
<!-- Inline PDF embed -->
<embed src="@Url.Action("DeletePreview","Imaging", new { id = Model.BatchIds[k] })#zoom=FitH"
type="application/pdf" />
<!-- Checkbox for selection -->
<div class="preference">
<label>Select</label>
<input type="checkbox" name="docIds"
value="@Model.BatchIds[k]"
id="[@k].docIds"
class="form-check-input" />
</div>
<!-- Trigger for full-screen modal -->
<a href="javascript:void(0);"
class="previewDetail2"
data-id="@Model.BatchIds[k]">Preview</a>
</div>
</div>
counter++;
}
</div>
embedtag shows a mini-preview.- Checkbox name
docIdsmaps to controller’s expected parameter. Previewlink has adata-idattribute for AJAX modal loading.
3.4 Deletion Workflow 🗑️
A form wraps the grid:
@using (Html.BeginForm("Delete", "HRImaging", FormMethod.Post, Model)) {
@Html.HiddenFor(m => m.DocumentImageId)
@Html.HiddenFor(m => m.BatchIds)
<input type="hidden" asp-for="DeleteFiles" />
<!-- Top delete button -->
<button type="submit" onclick="deleteFiles();" class="btn btn-danger">
Delete Selected Documents
</button>
<!-- Grid of documents... -->
<!-- Bottom delete button -->
<button type="submit" onclick="deleteFiles();" class="btn btn-danger">
Delete Selected Documents
</button>
}
- Two delete buttons (top & bottom) for convenience.
- Hidden field
DeleteFilesis set toTrueby thedeleteFiles()JS handler. - On submission, the controller’s
Deleteaction processes the selecteddocIds.
3.5 Modal Preview & AJAX ⚡
Modal Markup (hidden by default):
<div id="myModal" class="modal">
<div class="modal-dialog">
<div class="modal-content">
<div id="myModalContent"></div>
</div>
</div>
</div>
JavaScript Logic:
<script type="text/javascript">
function deleteFiles() {
if (!confirm("Are you sure you want to delete the selected documents?"))
return false;
$("#DeleteFiles").val("True");
}
var TeamDetailPostBackURL = '/Imaging/myModalDeletePreview';
$(function () {
$(".previewDetail2").click(function () {
var id = $(this).data('id');
$.ajax({
type: "GET",
url: TeamDetailPostBackURL,
data: { id: id, Preview: true },
success: function (html) {
$('#myModalContent').html(html);
$('#myModal').modal('show');
},
error: function () {
alert("Dynamic content load failed.");
}
});
});
});
</script>
deleteFiles()pops up a confirmation dialog & sets the hidden flag.- Ajax GET to
/Imaging/myModalDeletePreviewloads full preview into the modal.
4. ViewModel & Data Models
namespace IrbyImaging.Models
{
public class DocumentImaging
{
public Guid DocumentImageId { get; set; }
public List<Guid> BatchIds { get; set; }
public bool DeleteFiles { get; set; }
}
}
BatchIds: List of document GUIDs for display and deletion.DeleteFiles: Bound to a hidden input; toggled by JS to indicate deletion.
5. Hidden Fields & Form Elements
| Element | Purpose |
|---|---|
@Html.HiddenFor(m => m.DocumentImageId) |
Retain parent document reference. |
@Html.HiddenFor(m => m.BatchIds) |
Persist the full list of IDs. |
<input type="hidden" asp-for="DeleteFiles" /> |
Flag to controller that deletion is intended. |
6. Sample Code Snippets
Controller: Rendering the View
public class HRImagingController : Controller
{
[HttpGet]
public IActionResult DeleteUploadedDocument(Guid documentImageId)
{
// e.g. retrieve associated batch IDs for this document
var batchIds = _documentService.GetBatchIds(documentImageId);
var model = new DocumentImaging
{
DocumentImageId = documentImageId,
BatchIds = batchIds,
DeleteFiles = false
};
return View(model);
}
}
Controller: Handling Deletion
[HttpPost]
public IActionResult Delete(DocumentImaging model, List<Guid> docIds)
{
if (model.DeleteFiles && docIds?.Any() == true)
{
foreach (var id in docIds)
_documentService.DeleteDocumentById(id);
}
// Redirect back to index or confirmation page
return RedirectToAction("Index");
}
7. UML & Sequence Diagrams 📊
sequenceDiagram
participant U as User
participant V as DeleteUploadedDocument.cshtml
participant C as HRImagingController
participant S as DocumentService
U->>C: GET /HRImaging/DeleteUploadedDocument?documentImageId={id}
C->>S: GetBatchIds(id)
S-->>C: List<Guid>
C-->>U: Razor View (model)
U->>V: Click [Preview]
V->>C: AJAX GET /Imaging/myModalDeletePreview?id={docId}&Preview=true
C->>S: GetDocumentPreview(docId)
S-->>C: Partial View HTML
C-->>V: Partial View (in modal)
U->>V: Select checkboxes + Click [Delete]
V->>U: JavaScript confirm()
U->>V: Confirm true
V-->>C: POST /HRImaging/Delete (model + docIds)
C->>S: DeleteDocumentById(id) [loop]
S-->>C: DeletionResult
C-->>U: Redirect / Index
8. Usage Example
- Navigate to
/HRImaging/DeleteUploadedDocument?documentImageId={GUID}. - View thumbnails of each PDF in a 4‑column grid.
- Click ✓ on desired documents to delete.
- Click “Delete Selected Documents”.
- Confirm the browser prompt.
- Observe redirect to list or confirmation page.
9. Conclusion
The DeleteUploadedDocument.cshtml view is a complete, user‑friendly interface for managing and deleting batches of uploaded documents. It blends Razor model binding, Bootstrap styling, embedded PDF previews, modal dialogs, and jQuery AJAX to deliver a seamless experience. Developers can extend it by:
- Adding paging or lazy‑loading for large batches.
- Customizing the modal template to include metadata.
- Integrating server‑side validation or audit logging on deletion.
🎉 Happy coding!