SaveDocument.cshtml đ
Path:
IrbyImaging/Views/HRImaging/SaveDocument.cshtml
Purpose: Render the âSave Uploaded Documentâ page for the HR Imaging module. It allows users to preview scanned PDFs, select document types, retrieve index metadata fields dynamically, and then save the document along with its indexing information.
Table of Contents đ
- Overview & Purpose
- Dependencies & Technologies
- Data Models & ViewModels
- Layout & Sections
- Key Functional Areas
- ThirdâParty Integrations & Plugins
- Sample Code Blocks
- Usage Examples
- Error Handling & Validation
- UML Sequence Diagram
- Conclusion
Overview & Purpose đ
This Razor view is part of the HRImaging area in the IrbyImaging solution. It enables:
- PDF Preview: Displaying the scanned document for visual confirmation.
- DocumentâType Selection: Allowing the user to pick a
DocumentTypefrom a dropdown. - Index Metadata Retrieval: Fetching a dynamic set of fields (text, date, number, selects) based on the chosen document type.
- Metadata Entry & Save: Capturing userâentered metadata (indexes) and saving the document batch with all associated data.
- Access Control: Adding user roles (via multiselect) that can view/manage the document.
Dependencies & Technologies âď¸
| Technology / Library | Purpose |
|---|---|
| ASP.NET Core MVC (Razor) | Serverâside view rendering |
| Syncfusion EJ2 / ejsâmultiselect | Rich JavaScript dropdown & multitple select UI |
| jQuery | DOM manipulation & event handling |
| Select2 | Enhanced <select> with search/filtering |
| Bootstrap Datepicker | Dateâpicker styling & functionality |
| Dropzone.js | (Prepared CSS included â for dragâdrop uploads) |
| Newtonsoft.Json | JSON serialization (if needed) |
Data Models & ViewModels đ
public class DocumentImaging
{
public Guid DocumentImageId { get; set; }
public string FilePath { get; set; }
public string Preview { get; set; }
public IList<Guid> BatchIds { get; set; }
public Guid ReferenceId { get; set; }
public string ContentType { get; set; }
public string IndexTag { get; set; }
// Populated on initial GET
public IEnumerable<SelectListItem> DocumentTypes { get; set; }
// Populated after âGet Indexesâ POST
public IList<IndexField> IndexList { get; set; }
// Data sources for linked dropdowns
public IEnumerable<SelectListItem> EmployeeData { get; set; }
public IEnumerable<SelectListItem> JobData { get; set; }
public IEnumerable<SelectListItem> CustomerData { get; set; }
public IEnumerable<SelectListItem> StateData { get; set; }
// For multiâvalue fields (boolean, list, etc.)
public IEnumerable<SelectListItem> MultiValueTypes { get; set; }
}
public class IndexField
{
public Guid Id { get; set; }
public string AttributeName { get; set; }
public AttributeType AttributeType { get; set; }
public bool IsMultiValue { get; set; }
public bool IsRequired { get; set; }
public bool LinkEmployeeData { get; set; }
public bool LinkJobData { get; set; }
public bool LinkCustomerData { get; set; }
public string IndexValue { get; set; }
public IEnumerable<SelectListItem> MultiValueTypes { get; set; }
}
Layout & Sections đ¨
- Layout:
~/Views/Shared/_Layout.cshtml - Title: Set via
ViewData["Title"] = "Save Uploaded Document" - Sections:
@section styles { ⌠}â includes CSS for datepicker & Dropzone.@section Scripts { ⌠}â loads jQuery, Select2 CSS/JS, and initializes Select2 on<select>s.
Key Functional Areas đ
1. Document Type Selection & âGet Indexesâ đ
<form asp-action="SaveDoc" method="post" id="validation-form">
@Html.HiddenFor(m => m.DocumentImageId)
@Html.HiddenFor(m => m.FilePath)
@Html.HiddenFor(m => m.Preview)
@Html.HiddenFor(m => m.BatchIds, new { Value = lists })
@Html.AntiForgeryToken()
<h4>Select Document Type</h4>
<select asp-for="DocumentType" asp-items="@Model.DocumentTypes"
class="form-control">
<option disabled selected>Select Document Type</option>
</select>
<input type="hidden" id="batchId" value="@guidList" />
<button type="submit" id="searchDocument"
class="btn btn-primary">Get Indexes</button>
</form>
- Hidden fields: Pass along batch IDs, file path, preview URI.
- Dropdown:
<select>lists all available document types fromModel.DocumentTypes. - Submit: Calls
HRImagingController.SaveDocto load the relevant index fields.
2. PDF Preview đ
<embed id="frPDF"
src="@Url.Action("DocumentPreview","HRImaging", new { id = indexTagId })#zoom=FitH"
width="100%" height="800px" type="application/pdf" />
- Displays the scanned PDF inside an
<embed>tag. indexTagIdensures the PDF is referenced correctly in the controller.
3. Dynamic Indexing Form & Save âď¸
@if (Model.IndexList.Any())
{
<form asp-action="Save" method="post" id="validation-form">
@* Hidden fields to carry context *@
@Html.HiddenFor(m => m.DocumentType)
@Html.HiddenFor(m => m.HRDocumentType)
@Html.HiddenFor(m => m.BatchIds, new { Value = lists })
@Html.AntiForgeryToken()
<h4>Search Documents (Metadata Entry)</h4>
@for (var i = 0; i < Model.IndexList.Count; i++)
{
var field = Model.IndexList[i];
// 1) Emit hidden metadata about each field
<input type="hidden" asp-for="@field.Id" />
<input type="hidden" asp-for="@field.AttributeType" />
// 2) Render input UI according to AttributeType & flags
@* e.g., Textarea, <select> with EmployeeData, date input, number input, etc. *@
}
<label>Add Roles</label>
<ejs-multiselect id="roles" dataSource="ViewBag.Roles" placeholder="Select a Role">
<e-multiselect-fields text="Name" value="RoleId"></e-multiselect-fields>
</ejs-multiselect>
<input type="hidden" id="batchId" value="@guidList" />
<button type="submit" class="btn btn-primary">Save Document</button>
</form>
}
-
Dynamic Field Rendering:
- Text/Character â
<textarea> - Date â
<input type="date"> - Number/Currency â
<input type="number">(+ â$â prefix for currency) - Boolean â
<select>with Yes/No - Linked Data (Employee/Job/Customer/State) â
<select>populated fromModel.EmployeeData, etc. - Multiâvalue â
<select>withModel.MultiValueTypes.
- Text/Character â
-
Roles Multiselect:
Uses Syncfusion<ejs-multiselect>to assign roles that can access/manage the document.
ThirdâParty Integrations & Plugins đ
| Plugin | Usage |
|---|---|
| Syncfusion EJ2 | <ejs-multiselect> for roles & other linked lists. |
| Select2 | Enhanced singleâselect styling & search. |
| Bootstrap Datepicker | CSS is included (JS can be added if needed). |
| Dropzone (CSS only) | Prepared for dragâandâdrop upload UIs. |
Initialization snippet for Select2:
@section Scripts {
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<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>
}
Sample Code Blocks đť
Controller Actions (illustrative):
public class HRImagingController : Controller
{
[HttpGet]
public IActionResult SaveDocument(Guid referenceId, List<Guid> batchIds)
{
var model = new DocumentImaging {
ReferenceId = referenceId,
BatchIds = batchIds,
DocumentTypes = _service.GetDocumentTypes()
};
return View(model);
}
[HttpPost]
public IActionResult SaveDoc(DocumentImaging model)
{
// 1. Validate DocumentType
// 2. Load dynamic IndexList from DB
model.IndexList = _service.GetIndexFields(model.DocumentType);
// repopulate lookups
model.EmployeeData = _service.GetEmployees();
// ...
return View("SaveDocument", model);
}
[HttpPost]
public IActionResult Save(DocumentImaging model)
{
if (!ModelState.IsValid)
return View("SaveDocument", model);
_service.SaveIndexedDocument(model);
return RedirectToAction("Index", "HRImaging");
}
}
Usage Examples đĽď¸
-
Initial Access
GET/HRImaging/SaveDocument?referenceId={docGuid}&batchIds={guid1,guid2} -
Retrieve Index Fields
After selecting a type and clicking Get Indexes, POST to:/HRImaging/SaveDoc -
Save Completed Document
When metadata is filled, clicking Save Document triggers POST to:/HRImaging/Save
Error Handling & Validation â
@Html.ValidationSummary(true)displays modelâlevel errors at the top.- Each input control can be decorated with data annotations for fieldâlevel validation.
- On form POSTs, serverâside validation (
ModelState.IsValid) must be checked in controller actions. - AntiâForgery token (
@Html.AntiForgeryToken()) protects against CSRF attacks.
UML Sequence Diagram đ
@startuml
actor User
User -> SaveDocumentView : GET /HRImaging/SaveDocument
SaveDocumentView -> Controller : SaveDocument(referenceId, batchIds)
Controller -> Service : GetDocumentTypes()
Service --> Controller : List<SelectListItem>
Controller -> SaveDocumentView : view(model)
User -> SaveDocumentView : Select Type + Get Indexes
SaveDocumentView -> Controller : POST /SaveDoc
Controller -> Service : GetIndexFields(documentType)
Service --> Controller : IndexList
Controller -> SaveDocumentView : view(model with IndexList)
User -> SaveDocumentView : Fill metadata + Save
SaveDocumentView -> Controller : POST /Save
Controller -> Service : SaveIndexedDocument(model)
Service --> Controller : Success
Controller -> User : RedirectToAction(Index)
@enduml
Conclusion đ
The SaveDocument.cshtml view is a rich, dataâdriven interface for capturing and saving scanned HR documents with their metadata. It leverages:
- Twoâstep workflow: select/documentâtype â retrieve metadata fields â save.
- Dynamic form generation based on
IndexList. - Inline PDF preview for user validation.
- Thirdâparty widgets (Syncfusion, Select2) for an enhanced UX.
By following this pattern, you can easily extend support for new document types, metadata attributes, or integrate additional lookup sources. Happy coding!