📄 SaveDocument.cshtml Documentation
Welcome to the detailed documentation for the SaveDocument.cshtml Razor view in the IrbyImaging project. This view is part of the AccountingImaging area and is responsible for presenting users with the UI to select a document type, provide index metadata, preview the PDF, and ultimately save the uploaded document to the system.
Table of Contents
- Overview & Purpose
- File Location & Naming
- View Model
- Dependencies & Technologies
- Key Functional Areas
5.1. Model Initialization
5.2. Styles Section
5.3. “Get Indexes” Form
5.4. PDF Preview Embedding
5.5. “Save Document” Form
5.6. Scripts Section - Controller Interactions & API Endpoints
- Data Flow & Sequence Diagram
- Third-Party Integrations
- Sample Usage & Code Snippets
- Conclusion
Overview & Purpose
SaveDocument.cshtml serves as the primary user interface for accounting staff to:
- Select a document type (Invoice, PO, etc.)
- Fetch the required indexing fields dynamically
- Enter metadata values (text, date, number, dropdowns)
- Preview the uploaded PDF in-browser
- Save the fully indexed document back to the server
This two-step form process ensures that users only see relevant indexing fields after choosing a document type, improving data quality and user experience. 🚀
File Location & Naming
- Path:
IrbyImaging/Views/AccountingImaging/SaveDocument.cshtml - ViewBag Title:
"Save Uploaded Document"
View Model
This view is strongly-typed to the IrbyImaging.Models.DocumentImaging model.
| Property | Type | Description |
|---|---|---|
| DocumentImageId | Guid |
Unique ID of the document image record |
| ReferenceId | string |
Logical reference/business ID |
| FilePath | string |
Server path to the uploaded file |
| Preview | bool |
Flag to indicate inline preview |
| BatchIds | List<Guid> |
List of batch GUIDs for multi-upload cases |
| ImagingType | string |
e.g., "Accounting" |
| DocumentTypes | SelectList |
Dropdown for available document types |
| IndexList | List<IndexField> |
Dynamic indexing metadata definitions |
| EmployeeData, JobData, CustomerData, StateData | SelectList |
Data sources for dropdown fields |
Note:
IndexFieldincludes properties such asAttributeName,AttributeType,IsMultiValue,LinkEmployeeData, etc.
Dependencies & Technologies
| Category | Details / Packages |
|---|---|
| UI Framework | Bootstrap (cards, grid, form controls) |
| Client-Side Libraries | jQuery, Select2 |
| Date Picker | bootstrap-datepicker |
| File Upload Styles | dropzone |
| PDF Embedding | <embed> tag with query #zoom=FitH |
| Syncfusion (commented) | Syncfusion.JavaScript, Syncfusion.EJ2 |
| JSON Handling | Newtonsoft.Json |
| Razor View Engine | ASP.NET Core MVC |
Key Functional Areas
5.1 Model Initialization
@model IrbyImaging.Models.DocumentImaging
@using Syncfusion.JavaScript
@using Newtonsoft.Json
@{
ViewData["Title"] = "Save Uploaded Document";
var lists = Model.BatchIds;
var docId = Model.ReferenceId;
string guidList = string.Join(",", lists);
var filePath = Model.FilePath;
var indexTagId= Model.IndexTag;
string type = Model.ContentType;
}
- BatchIds are combined into a comma-delimited string (
guidList) for hidden fields. - ViewData["Title"] sets the page title.
5.2 Styles Section
@section styles {
<!-- Datepicker CSS -->
<link href="~/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" />
<!-- Dropzone CSS -->
<link href="~/libs/dropzone/min/dropzone.min.css" rel="stylesheet" />
}
- Includes datepicker and dropzone styles for potential date selection and drag-n-drop uploads.
5.3 “Get Indexes” Form
<form asp-action="SaveDoc" method="post" class="form-horizontal" id="validation-form">
@* Hidden metadata *@
@Html.HiddenFor(m => m.DocumentImageId)
@Html.HiddenFor(m => m.FilePath)
@Html.Hidden("batchId", guidList)
<!-- Document Type Selector -->
<select asp-for="DocumentType" asp-items="@Model.DocumentTypes" class="form-control">
<option disabled selected>Select Document Type</option>
</select>
<!-- Fetch Buttons -->
<button id="searchDocument" class="btn btn-primary">Get Indexes</button>
</form>
- Purpose: Upon selecting a document type and clicking Get Indexes, the controller will return the view with
Model.IndexListpopulated. - Action:
AccountingImagingController.SaveDoc(...)
5.4 PDF Preview Embedding
<embed id="frPDF"
src="@Url.Action("DocumentPreview","AccountingImaging", new { id = indexTagId })#zoom=FitH"
type="application/pdf"
width="100%" height="100%">
- Embeds an in-browser PDF preview.
- Uses AccountIngImagingController.DocumentPreview(id) to stream the PDF.
5.5 “Save Document” Form
Once Model.IndexList.Count > 0, render dynamic indexing fields:
<form asp-action="Save" method="post" id="validation-form">
@Html.AntiForgeryToken()
@Html.HiddenFor(m=>m.DocumentImageId)
@Html.Hidden("batchId", guidList)
@foreach(var field in Model.IndexList) {
<!-- Decide control type based on field.AttributeType, IsMultiValue, or Link* flags -->
@if(field.AttributeType == AttributeType.Text && !field.IsMultiValue) {
<textarea asp-for="@field.IndexValue"></textarea>
}
else if(field.LinkEmployeeData) {
<select asp-for="@field.IndexValue" asp-items="@Model.EmployeeData" class="js-example-basic-single"></select>
}
<!-- … other cases: Date, Number, Currency, Boolean, MultiValue, State, etc. -->
}
<button id="saveDocument" class="btn btn-primary">Save Document</button>
</form>
- Dynamic Rendering:
- TextArea for long text
- Date input for
AttributeType.Date - Number / Currency inputs
- Select2-enhanced dropdowns for employee/job/customer/state lists
- Boolean dropdown (Yes/No)
- Action:
AccountingImagingController.Save(...)
5.6 Scripts Section
@section Scripts {
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('.js-example-basic-single').select2();
});
</script>
}
- Select2 initialization for enhanced dropdown UX.
Controller Interactions & API Endpoints
| Endpoint | HTTP | Purpose |
|---|---|---|
| /AccountingImaging/SaveDocument | GET | Show initial form |
| /AccountingImaging/SaveDoc | POST | Populate IndexList based on doc type |
| /AccountingImaging/Save | POST | Persist the document and metadata |
| /AccountingImaging/DocumentPreview/{id} | GET | Return PDF stream for embedding |
Data Flow & Sequence Diagram
sequenceDiagram
User->>SaveDocument.cshtml: GET
SaveDocument.cshtml->>AccountingImagingController: Request form
AccountingImagingController-->>SaveDocument.cshtml: View(model)
User->>SaveDocument.cshtml: Select DocType + Get Indexes (POST)
SaveDocument.cshtml->>AccountingImagingController.SaveDoc: { DocumentType, BatchIds }
AccountingImagingController.SaveDoc-->>SaveDocument.cshtml: View(model with IndexList)
User->>SaveDocument.cshtml: Fill Fields + Save Document
SaveDocument.cshtml->>AccountingImagingController.Save: { all index values }
AccountingImagingController.Save-->>Server: Persist file & metadata
AccountingImagingController.Save-->>User: Redirect/Confirmation
Third-Party Integrations
- Select2: Improves dropdowns with searching & tagging
- Bootstrap Datepicker (CSS ready)
- Dropzone.js (CSS ready for future drag-n-drop)
- Syncfusion (commented out – can enable for advanced widgets)
Sample Usage & Code Snippets
1. Calling the View from Controller
public IActionResult SaveDocument(List<Guid> batchIds) {
var model = new DocumentImaging {
BatchIds = batchIds,
DocumentTypes = _docService.GetDocumentTypeSelectList(),
// ... other initializations ...
};
return View(model);
}
2. Handling “Get Indexes” (SaveDoc)
[HttpPost]
public IActionResult SaveDoc(DocumentImaging model) {
model.IndexList = _indexService.GetFieldsFor(model.DocumentType);
// Populate dropdown sources
model.EmployeeData = _lookupService.GetEmployeeSelectList();
// ...
return View("SaveDocument", model);
}
3. Persisting Data (Save)
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Save(DocumentImaging model) {
_documentService.Save(model);
return RedirectToAction("Index", "AccountingDashboard");
}
Conclusion
SaveDocument.cshtml is a dynamic, two-step Razor view designed for the Accounting Imaging module. By leveraging ASP.NET Core MVC features, client-side libraries (Select2, jQuery), and server-driven metadata (IndexList), it ensures a streamlined user experience for indexing and saving PDF documents. Whether you're adding a new document type or customizing indexing rules, this view provides a flexible foundation to meet evolving business requirements. 🎉
Happy Coding! 🚀