UploadTest.cshtml

# šŸ“„ UploadTest.cshtml Documentation

Welcome to the comprehensive documentation for **IrbyImaging/Views/Imaging/UploadTest.cshtml**. This document covers everything you need to know to understand, extend, and maintain the file‐upload view in the Imaging module.

---

## šŸ“‘ Table of Contents

1. [Overview & Purpose](#overview--purpose)  
2. [Key Functional Areas](#key-functional-areas)  
3. [Dependencies & Technologies](#dependencies--technologies)  
4. [View Models & Data Models](#view-models--data-models)  
5. [Helper Methods & Utilities](#helper-methods--utilities)  
6. [Error Handling & Return Types](#error-handling--return-types)  
7. [API Endpoints Overview](#api-endpoints-overview)  
8. [Third‐party Integrations](#third‐party-integrations)  
9. [Sample Code Blocks](#sample-code-blocks)  
10. [Usage Examples](#usage-examples)  
11. [UML Diagram](#uml-diagram)  
12. [Conclusion](#conclusion)  

---

## 1. Overview & Purpose

**UploadTest.cshtml** is an ASP.NET Core Razor view that provides a **Drag‑and‑Drop file upload** interface using [Dropzone.js](https://www.dropzonejs.com/). It allows users to select multiple files, preview them, and then upload all files in bulk.  

šŸŽÆ **Primary Goals**  
- Offer a modern, user-friendly file upload UI  
- Support multiple simultaneous uploads  
- Integrate seamlessly with the `ImagingController` (actions: `UploadTest` & `DocPreview`)  
- Provide client‐side hooks (via JavaScript events) for processing and post‐upload redirection  

---

## 2. Key Functional Areas

| Section                          | Description |
|----------------------------------|-------------|
| **Razor Layout & Metadata**      | Sets page titles (`ViewBag.Title`, `pTitle`, `pageTitle`) and defines the layout (`_Layout.cshtml`). |
| **Styles Section**               | Injects Dropzone CSS into the `<head>` via `@section styles`. |
| **HTML Markup**                  | Contains the `<form>` with `class="dropzone"` plus a fallback `<input>` for non-JS clients. |
| **Action Buttons**               | A ā€œUpload Documentsā€ `<button>` to manually trigger the Dropzone queue processing. |
| **Script Imports**               | Loads jQuery, Bootstrap, Dropzone.js, and app-specific JS (`app.js`). |
| **Dropzone Configuration**       | Customizes param names, queuing, event handlers (`init`, `complete`, `completemultiple`). |

---

## 3. Dependencies & Technologies

- **ASP.NET Core MVC** (Razor Views)  
- **Dropzone.js v5.5.1** (for drag‑and‑drop uploads)  
- **jQuery** (v3.x) & **Bootstrap 4+** (UI & grid system)  
- **MetisMenu**, **SimpleBar**, **Waves** (layout & interactivity)  
- **_Layout.cshtml** (global site layout)

---

## 4. View Models & Data Models

This view does not bind a strongly‐typed model. Instead, it leverages:

- **Form fields**: `<input name="file" type="file" multiple />`  
- **Dropzone auto‐processed files** sent as `file` (see `paramName` logic below)

If you wish to extend it with a ViewModel, you could create:

```csharp
public class UploadTestViewModel
{
  public IEnumerable<IFormFile> Files { get; set; }
  // Additional metadata, e.g. Category, Tags…
}

5. Helper Methods & Utilities

JavaScript Helper: myParamName()

function myParamName() {
  return "file";
}
  • Purpose: Defines the parameter name used when Dropzone sends files to the server.
  • Usage: Assigned to paramName in Dropzone configuration.

6. Error Handling & Return Types

  • Dropzone’s accept(file, done) callback is used for client‐side validation.
  • By default it calls done() (meaning ā€œallow this fileā€).
  • To reject a file, call done("Error message").
  • On upload error, Dropzone will display the error text automatically.

7. API Endpoints Overview

This view interacts with two actions on the ImagingController:

Action HTTP Method URL Purpose
UploadTest POST /Imaging/UploadTest Receives the uploaded files, processes them server-side.
DocPreview GET /Imaging/DocPreview Displays a preview of the uploaded document, receives ?fileName= query.

šŸ’” Note: The actual controller methods must accept IFormFileCollection or similar to handle the upload.


8. Third‑party Integrations

  • Dropzone.js
  • CDN: Dropzone is loaded from cdnjs.cloudflare.com
  • MetisMenu, SimpleBar, Waves for sidebars and ripple effects.

9. Sample Code Blocks

Razor Markup Snippet

@{
    ViewBag.Title     = "Form File Upload";
    ViewBag.pTitle    = "Form File Upload";
    ViewBag.pageTitle = "Forms";
    Layout            = "~/Views/Shared/_Layout.cshtml";
}

@section styles {
  <link href="~/assets/libs/dropzone/min/dropzone.min.css" rel="stylesheet" />
}

<div class="card">
  <div class="card-body">
    <h4 class="card-title mb-4">Upload Documents</h4>
    <form method="post"
          enctype="multipart/form-data"
          asp-controller="Imaging"
          asp-action="UploadTest"
          class="dropzone"
          id="dropzone-form"
          name="mainFileUploader">
      <div class="fallback">
        <input name="file" type="file" multiple />
      </div>
      <div class="dz-message needsclick">
        <i class="display-4 text-muted bx bxs-cloud-upload"></i>
        <h4>Drop files here or click to upload.</h4>
      </div>
    </form>
    <button id="uploadfile" class="btn btn-primary mt-3">
      Upload Documents
    </button>
  </div>
</div>

Dropzone Initialization

Dropzone.options.dropzoneForm = {
  paramName: myParamName,         // sets `file` as the input name
  autoProcessQueue: false,        // manual upload trigger
  uploadMultiple: true,           // allow multiple files
  parallelUploads: 100,           // concurrency
  addRemoveLinks: true,
  init: function () {
    var dz = this;
    $("#uploadfile").click(function (e) {
      e.preventDefault();
      dz.processQueue();
    });
    dz.on("complete", function(file) {
      dz.removeAllFiles();
      window.location.href = '@Url.Action("DocPreview","Imaging")?fileName=' + file.name;
    });
  },
  accept: function(file, done) {
    done(); // always accept
  }
};

10. Usage Examples

  1. Navigate to /Imaging/UploadTest in your browser.
  2. Drag & drop files into the gray box, or click to open the file dialog.
  3. Once your files appear, click Upload Documents.
  4. After upload, you will be redirected to /Imaging/DocPreview?fileName={yourFile}).

11. UML Diagram

+---------+       +-------------+       +---------------+
| Browser | --POST--> UploadTest  | -->> | ImagingController  |
+---------+       +-------------+       +---------------+
     |                                         |
     | <—Redirect `/DocPreview?fileName=...`   |
     +-----------------------------------------+

šŸ“ˆ Sequence:

  1. User triggers processQueue().
  2. Dropzone sends file payload to Imaging/UploadTest.
  3. Server processes and returns 200 OK.
  4. Client JS redirects to DocPreview.

12. Conclusion

This documentation covered the UploadTest.cshtml view in detail. You learned:

  • How the Razor markup and Dropzone integration work
  • Which dependencies are involved
  • Where the uploads go (controller endpoints)
  • How to extend or customize the UI & JS

Feel free to modify the accept callback for validation, adjust parallelUploads for performance, or enrich the ViewModel to include metadata alongside your files. Happy coding! šŸš€