📄 SaveDocument.cshtml Documentation
Welcome to the detailed documentation for the SaveDocument.cshtml Razor view in the IrbyImaging application. This document covers the purpose, structure, dependencies, data flow, and usage examples for this view.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- ViewModel & DataModel
- Key Functional Areas
- API Endpoints Overview
- Helper Methods & Utilities
- Error Handling & Validation
- Third-party Integrations
- Sample Code Blocks
- Usage Examples
- UML Diagrams
- Conclusion
1. Overview & Purpose 🚀
SaveDocument.cshtml is a Razor view responsible for rendering a form that allows users to save metadata associated with an uploaded document and to preview the PDF inline.
- Use Case: After a document is uploaded into the system, the user needs to classify it (type, job, employee, notes, date) and then save those details.
- Key Features:
- Dynamic dropdowns (Document Type, Job, Employee)
- Date picker for document date
- Inline PDF preview
- Client‑side enhancements with Select2 and Bootstrap Datepicker
2. Dependencies & Technologies 🔧
| Category | Library / Tool |
|---|---|
| Front‑end CSS | Bootstrap 5, Dropzone.css, Bootstrap-datepicker.css |
| Front‑end JS | jQuery, Select2, Bootstrap.bundle, MetisMenu, SimpleBar, Waves, TinyMCE, jQuery Repeater |
| Razor / .NET | ASP.NET Core MVC, Razor Pages |
| PDF Preview | <embed> tag with controller endpoint |
| Custom Scripts | ~/js/app.js, ~/js/pages/task-create.init.js |
3. ViewModel & DataModel 🧮
@model IrbyImaging.Models.DocumentImaging
DocumentImaging (simplified)
| Property | Type | Description |
|---|---|---|
| DocumentImageId | Guid |
Unique ID of the uploaded document |
| BatchIds | List<Guid> |
Identifiers for batch processing |
| ReferenceId (IndexTag) | string |
Tag used for PDF preview |
| DocumentType | string |
User‑selected document category |
| JobNumber, JobName, … | string |
Metadata fields filled by user |
| DocumentUploadedDate | DateTime |
Date of the document |
| DocumentNotes | string |
Additional descriptive notes |
Note: Additional navigation data is passed via
ViewBag.JobNamesandViewBag.Employeesfor populating dropdowns.
4. Key Functional Areas ⚙️
4.1 Form Structure & Hidden Fields
@using (Html.BeginForm("Save", "Imaging", FormMethod.Post)) {
@Html.HiddenFor(m => m.DocumentImageId)
@Html.HiddenFor(m => m.BatchIds, new { Value = lists })
@Html.HiddenFor(m => m.IndexTag)
<!-- ... rest of form ... -->
}
- Hidden Inputs hold IDs required on post back (
DocumentImageId,BatchIds,IndexTag). - Form Action: Posts to
ImagingController.Save(DocumentImaging model).
4.2 Document Metadata Inputs
All inputs are wrapped in Bootstrap rows & cards for responsive layout:
- Document Type:
<select asp-for="DocumentType" class="form-select"> <option>Select Type</option> <option>ANNUAL CRANE INSPECT REP</option> <!-- … other types … --> </select> - Job Number & Name:
JobNumberListis a searchable Select2 dropdown bound toViewBag.JobNames.- On change, JavaScript splits the selected value to populate
JobName.
- Employee Id & Name:
EmployeeIdis a Select2 dropdown fromViewBag.Employees.- On selection, JS extracts name and sets both
AssignedToEmployeeNameandCompletedBy.
- Date Picker for
DocumentUploadedDate:@Html.TextBoxFor(m => m.DocumentUploadedDate, "{0:d}", new {type="date"})
4.3 PDF Preview Pane
<embed id="frPDF" src="@Url.Action("DocumentPreview","Imaging", new { id = indexTagId })#zoom=FitH" type="application/pdf" width="100%" height="100%">
- Loads the PDF using the
DocumentPreviewaction on the Imaging controller. - Zoom to fit width (
#zoom=FitH).
4.4 Submit Button
<button type="submit" onclick="return SubmitForm();" id="saveDocument" class="btn btn-primary">
Save Document
</button>
- Client Confirmation (commented-out).
- Triggers form submission.
5. API Endpoints Overview 🔗
| Endpoint | Method | Description |
|---|---|---|
| /Imaging/Save | POST | Saves the DocumentImaging model |
| /Imaging/DocumentPreview?id={id} | GET | Returns the PDF byte stream for preview |
6. Helper Methods & Utilities 🛠️
- JavaScript Setup in
@section Scripts- Initialize Select2:
$('#JobNumberList, #DocumentType, #EmployeeId').select2(); - Change Handlers for Job & Employee dropdowns to populate related fields.
- Initialize Select2:
- CSS Includes in
@section styles<link href="~/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" /> <link href="~/libs/dropzone/min/dropzone.min.css" rel="stylesheet" />
7. Error Handling & Validation ⚠️
- Razor Validation:
@Html.ValidationMessageFor(model => model.DocumentUploadedDate, "", new { @class = "text-danger" }) - Client‑side:
- Optionally confirm saves via
SubmitForm()(commented code). - Select2 prevents invalid values by restricting to provided options.
- Optionally confirm saves via
8. Third-party Integrations 🔌
| Library | Purpose |
|---|---|
| Select2 | Enhanced searchable dropdowns |
| Bootstrap Datepicker | Date selection widget |
| TinyMCE | Rich text (currently not used) |
| Dropzone | File upload styles (unused here) |
| jQuery Repeater | Dynamic form groups (unused) |
9. Sample Code Blocks 📋
Document Type Dropdown
<select asp-for="DocumentType" class="form-select">
<option>Select Type</option>
<option>ANNUAL DOT INSPECTION</option>
<!-- more options… -->
</select>
JavaScript: Populating Job Name
$('#JobNumberList').on("change", function () {
var job = $(this).val();
const [first, ...rest] = job.split('-');
$('#JobName').val(rest.join('-'));
});
10. Usage Examples ✍️
- Controller Action to display the view:
public IActionResult SaveDocument(Guid documentImageId) { var model = _service.GetDocumentImaging(documentImageId); ViewBag.JobNames = new SelectList(_service.GetJobs(), "Value", "Text"); ViewBag.Employees = new SelectList(_service.GetEmployees(), "Value", "Text"); return View("SaveDocument", model); } - Saving in Controller:
[HttpPost] public IActionResult Save(DocumentImaging model) { if (!ModelState.IsValid) return View(model); _service.SaveDocumentMetadata(model); return RedirectToAction("Index"); }
11. UML Diagrams 🗂️
Sequence Diagram
sequenceDiagram
participant U as User
participant V as SaveDocument.cshtml
participant C as ImagingController
U->>V: GET /Imaging/SaveDocument
V->>U: Render form with Model
U->>V: Fill form & Submit
V->>C: POST /Imaging/Save
C-->>V: Redirect or Error
V->>U: Show result or reload form
12. Conclusion 🎯
SaveDocument.cshtml is a central view for capturing document metadata and previewing uploaded PDFs within the IrbyImaging system. By leveraging ASP.NET Core MVC, Bootstrap, and Select2, it provides a user-friendly interface for classification and storage of critical documents. Use the examples and patterns above to integrate, customize, or extend its behavior for your organization’s workflow.
Thank you for using the IrbyImaging documentation! For further questions or contributions, please refer to the project’s README or contact the development team.