📄 IrbyImaging/Views/Imaging/Upload.cshtml Documentation
🎯 Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Models & Data Models
- Helper Methods & Utilities
- Error Handling & Return Types
- API Endpoints Overview
- Third‑party Integrations
- Sample Code Blocks
- Usage Examples
- UML Diagram
- Conclusion
1. Overview & Purpose
The Upload.cshtml Razor View is designed to provide a user-friendly interface for uploading one or multiple documents/images in the IrbyImaging system. It leverages both a classic form-based file input and the powerful Dropzone.js library for drag‑and‑drop uploads.
Key objectives:
- Let users browse or drag & drop files.
- Display a loading overlay & spinner during upload.
- Redirect to a preview page on completion.
2. Key Functional Areas
| Area | Description |
|---|---|
| Page Configuration | Sets the page title, layout & section styles via ViewBag and Layout. |
| Styles Injection | Includes Dropzone.css within the styles section. |
| Classic File‑Upload Form | <form enctype="multipart/form-data"> with <input type="file" multiple />. |
| Drag‑and‑Drop Upload (Dropzone.js) | Instantiates a Dropzone with custom options, event handlers & manual queue processing. |
| Loading Overlay & Spinner | Defines a full‑screen overlay (#loading) and uses spin.js for a spinner. |
| JavaScript Initialization | Loads jQuery, Bootstrap, Dropzone.js, custom scripts, and configures behaviors. |
3. Dependencies & Technologies
| Technology/Library | Purpose | Source |
|---|---|---|
| ASP.NET MVC Razor | Server‑side view templating | Built‑in |
| Dropzone.js | Drag‑and‑drop file uploads | CDN: https://cdnjs.cloudflare.com/.../dropzone.js |
| spin.js | Loading spinner on file submission | Local: ~/assets/js/spin.js |
| jQuery | DOM manipulation & event handling | ~/assets/libs/jquery/jquery.min.js |
| Bootstrap 5 | Responsive UI components | ~/assets/libs/bootstrap/js/bootstrap.bundle.min.js |
| MetisMenu | Side menu navigation | ~/assets/libs/metismenu/metisMenu.min.js |
| simplebar | Custom scrollbars | ~/assets/libs/simplebar/simplebar.min.js |
| Waves | Click ripple effects | ~/assets/libs/node-waves/waves.min.js |
4. View Models & Data Models
This view does not strongly type a ViewModel. It relies on the default MVC Controller → ViewBag pattern and multipart form data.
If you wish to extend it with a ViewModel, you could define:
public class UploadViewModel
{
[Display(Name="Select Files")]
public IFormFileCollection Files { get; set; }
}
And update the view declaration to:
@model IrbyImaging.Models.UploadViewModel
5. Helper Methods / Utilities
5.1 myParamName()
A small JavaScript helper to unify the Dropzone paramName config:
function myParamName() {
return "file";
}
This allows retrieving server‑side parameter by name file.
6. Error Handling & Return Types
- Client‑side
- Dropzone’s
accept(file, done)invokesdone()on success. To reject, calldone("Error message"). - On queue completion or upload success, UI resets files and performs a redirect.
- Dropzone’s
- Server‑side
- The form posts to
UploadNew(MVC action). On success, it should return an HTTP 302 to theDocPreviewpage. - On failure, return
View("Upload", model)with validation messages.
- The form posts to
7. API Endpoints Overview
| HTTP Method | URL | Controller.Action | Description |
|---|---|---|---|
| GET | /Imaging/Upload | Imaging.Upload() | Renders this upload view. |
| POST | /Imaging/UploadNew | Imaging.UploadNew() | Handles multipart form submission. |
| GET | /Imaging/DocPreview | Imaging.DocPreview() | Displays preview of uploaded file. |
8. Third‑party Integrations
- Dropzone.js for drag & drop and queue management
- spin.js for loading spinner customization
- CDN vs Local: Dropzone is loaded from CDN to ensure latest patch; spin.js is bundled locally.
9. Sample Code Blocks
9.1 Razor View Snippet (Form)
@using (Html.BeginForm(
"UploadNew",
"Imaging",
FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<input name="file" type="file" multiple class="form-control" style="height:400%" />
<button id="submitbtn" type="submit" class="btn btn-primary">Upload Documents</button>
}
9.2 Dropzone Configuration
Dropzone.options.dropzoneForm = {
paramName: myParamName,
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
init: function () {
var dz = this;
$("#uploadfile").click(() => dz.processQueue());
dz.on("complete", file => {
dz.removeAllFiles();
window.location.href =
'@Url.Action("DocPreview","Imaging")?fileName=' + file.name;
});
}
};
9.3 Loading Spinner (spin.js)
$("#submitbtn").click(() => {
$("#loading").fadeIn();
var spinner = new Spinner({
lines:19, length:28, width:7,
scale:0.05, speed:2.0, color:'#11467e'
}).spin(document.getElementById("loading"));
});
10. Usage Examples
- Navigate to
/Imaging/Upload. - Drag & Drop multiple files onto the input or click Browse.
- Click Upload Documents.
- A semi‑transparent loading overlay appears with a spinner.
- On success, you are redirected to DocPreview to view the uploaded file.
11. UML Diagram
sequenceDiagram
participant U as User
participant V as Upload.cshtml
participant C as ImagingController
participant S as DocPreview View
U->>V: GET /Imaging/Upload
V-->>U: Renders upload form
U->>V: POST files (form or Dropzone)
V->>C: HttpPost UploadNew(files)
C-->>V: Redirect to DocPreview?fileName=...
U->>S: GET /Imaging/DocPreview
S-->>U: Display preview
12. Conclusion
Upload.cshtml is a versatile, hybrid file‑upload view combining classic form submission with modern drag‑and‑drop capabilities. It integrates user experience enhancements like a loading spinner and customizable Dropzone options. By following the patterns shown, developers can easily extend, style, and handle server‑side processing for robust document management in the IrbyImaging system. 🚀