📄 UploadForm.cshtml Documentation
File Path: IrbyImaging/Views/IrbyForms/UploadForm.cshtml
🗂️ Table of Contents
- Overview & Purpose
- Layout & Structure
- Dependencies & Technologies
- View Model & Data Binding
- Form Markup (Key Functional Areas)
- Loading Spinner Implementation
- Client‑Side Scripts & Logic
- Third‑Party Integrations
- Sample Usage Example
- UML Sequence Diagram
- Conclusion
1. Overview & Purpose 🚀
UploadForm.cshtml is an ASP.NET Core Razor View that provides a user interface for uploading form files in the Irby Imaging application. Its responsibilities include:
- Letting users select a predefined form template.
- Letting users browse or drag‑and‑drop a file.
- Submitting the file(s) to the server via HTTP POST (
UploadFormsaction). - Displaying a loading spinner while the upload is in progress.
2. Layout & Structure 🏗️
@model IrbyImaging.UI.Models.IrbyFormsView
@{
ViewBag.Title = "Form File Upload";
ViewBag.pTitle = "Form File Upload";
ViewBag.pageTitle = "Forms";
Layout = "~/Views/Shared/_Layout.cshtml";
}
- Model Declaration: Strongly‑typed to
IrbyFormsView. - ViewBag: Sets the page titles and breadcrumbs.
- Layout: Reuses the shared site layout (
_Layout.cshtml).
3. Dependencies & Technologies 🔧
| Technology | Purpose |
|---|---|
| ASP.NET Core MVC Razor | Server‑side rendering of HTML |
| Bootstrap (CSS/JS) | Responsive grid, forms & components |
| jQuery | DOM manipulation & event handling |
| spin.js | Customizable loading spinner |
| metisMenu, simplebar, waves | Sidebar menu & UI enhancements |
4. View Model & Data Binding 📝
View Model: IrbyImaging.UI.Models.IrbyFormsView
| Property | Type | Description |
|---|---|---|
| FileName | string |
Identifier of the chosen form type |
| File | IFormFile |
Uploaded file instance |
Dropdown Binding
<select asp-for="FileName"
id="typeVal"
class="form-control col-sm-6"
asp-items="@ViewBag.Files">
</select>
asp-for="FileName"binds the selected value back to the view model.asp-items="@ViewBag.Files"populates options dynamically from the controller.
5. Form Markup (Key Functional Areas) 🖋️
<form asp-action="UploadForms"
id="myform"
method="post"
enctype="multipart/form-data">
<div class="card">
<div class="card-body">
<h4 class="card-title">Upload Forms</h4>
<!-- 1. Form Template Selector -->
<label class="col-form-label">Form Name</label>
<select asp-for="FileName" ...></select>
<!-- 2. File Upload Input -->
<label for="testdesc" class="col-form-label">Browse or Drop Files to Upload...</label>
<input asp-for="File"
name="file"
type="file"
class="form-control"
style="height:400%" />
<!-- 3. Submit Button -->
<button id="submitbtn"
type="submit"
class="btn btn-primary">
Upload
</button>
</div>
</div>
</form>
enctype="multipart/form-data": Required for file transmission.asp-action="UploadForms": Targets theUploadFormsaction in the controller.- Bootstrap
cardand grid utilities for responsive design.
6. Loading Spinner Implementation ⏳
A full‑screen overlay appears during the upload:
<div id="loading">
<div id="loadingcontent">
<p id="loadingspinner">
Upload in progress. Please wait.....
</p>
</div>
</div>
CSS
#loading {
display: none;
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
background: rgba(255,255,255,0.8);
z-index: 1000;
}
#loadingcontent {
display: table;
width: 100%; height: 100%;
}
#loadingspinner {
display: table-cell;
vertical-align: middle;
text-align: center;
font-size: larger;
padding-top: 80px;
}
7. Client‑Side Scripts & Logic 📜
$(function () {
$("#submitbtn").click(function () {
$("#loading").fadeIn();
var opts = {
lines: 19,
length: 28,
width: 7,
scale: 0.05,
corners: 1,
speed: 2.0,
color: '#11467e',
fadeColor: 'transparent'
};
var target = document.getElementById('loading');
new Spinner(opts).spin(target);
});
});
- On Document Ready: Binds click handler to
#submitbtn. - Show Overlay: Fades in
#loading. - Initialize Spinner: Uses spin.js with custom options.
Script Includes
<script src="~/assets/libs/jquery/jquery.min.js"></script>
<script src="~/assets/js/spin.js"></script>
<script src="~/assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/assets/libs/metismenu/metisMenu.min.js"></script>
<script src="~/assets/libs/simplebar/simplebar.min.js"></script>
<script src="~/assets/libs/node-waves/waves.min.js"></script>
<script src="~/assets/js/app.js"></script>
8. Third‑Party Integrations 🔗
- spin.js: Lightweight JavaScript spinner library.
- Bootstrap: Grid & form styling.
- jQuery: Simplified DOM events.
- MetisMenu / SimpleBar / Waves: UI menu and scroll enhancements.
9. Sample Usage Example 📋
Controller Actions (C#)
public class IrbyFormsController : Controller
{
// GET: Display the upload form
public IActionResult UploadForm()
{
ViewBag.Files = new SelectList(new[] { "FormA", "FormB", "FormC" });
return View();
}
// POST: Handle the file upload
[HttpPost]
public async Task<IActionResult> UploadForms(IrbyFormsView model)
{
if (!ModelState.IsValid)
return View("UploadForm", model);
var savePath = Path.Combine(_env.WebRootPath, "uploads", model.FileName);
using var fs = new FileStream(savePath, FileMode.Create);
await model.File.CopyToAsync(fs);
TempData["Success"] = "File uploaded successfully 😊";
return RedirectToAction("Index");
}
}
10. UML Sequence Diagram 🕹️
sequenceDiagram
participant U as User
participant V as UploadForm.cshtml
participant C as IrbyFormsController
participant S as FileSystem
U->>V: Fill form & click Upload
V->>V: Show loading overlay + spinner
V->>C: POST /UploadForms (form data + file)
C->>S: Save file to disk
S-->>C: Confirm write
C-->>U: Redirect / Response
V-->>V: Hide spinner (on new page load)
11. Conclusion 🏁
- UploadForm.cshtml delivers a smooth user experience for form file uploads.
- Built on ASP.NET Core Razor, Bootstrap, jQuery, and spin.js.
- Easily extensible for multiple-file uploads, progress bars, or drag‑and‑drop enhancements.
- Can be secured and validated further on the server side to ensure robust file handling.
Enjoy seamless file uploads in your Irby Imaging app! 🎉