📄 Documentation: EditType.cshtml
File Path:
IrbyImaging/Views/HRImaging/EditType.cshtml
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Model
- Layout & Metadata
- Form Structure & HTML Elements
- Third‑Party Components
- JavaScript Helpers & Utilities
- Error Handling & Validation
- Controller Interaction & Endpoints
- Sample Usage & Code Snippets
- UML Diagram of Data Model
- Conclusion
🔍 Overview & Purpose
This Razor view renders an Edit Document Type page in the HR Imaging area of the IrbyImaging application.
Users can update:
- The description of a document type
- Its category (dropdown)
- Associated index types (multi-select)
- Flags: IsAvailable & IsDeleted
It leverages ASP.NET Core MVC, data annotations for validation, and Syncfusion EJ2 controls for rich UI.
⚙️ Dependencies & Technologies
| Category | Details |
|---|---|
| Framework | ASP.NET Core MVC (Razor Views) |
| View Model | IrbyImaging.UI.Models.DocumentTypeView |
| Third‑Party Libraries | Syncfusion EJ2 (ejs-dropdownlist, ejs-multiselect) |
| JSON Serialization | Newtonsoft.Json |
| JS Utilities | ej.base, ej.data.Query (Syncfusion) |
| CSS/JS Bundles | Bootstrap, MetisMenu, SimpleBar, Node-Waves |
🧩 View Model
This view is strongly typed to the DocumentTypeView model:
namespace IrbyImaging.UI.Models
{
public class DocumentTypeView
{
public int Id { get; set; }
public string Type { get; set; }
public string Description { get; set; }
public int Category { get; set; }
public bool IsAvailable { get; set; }
public bool IsDeleted { get; set; }
public List<int> IndexTypes { get; set; }
}
}
📐 Layout & Metadata
@{
ViewBag.Title = "Edit Document Type";
ViewBag.pTitle = "Edit Document Types";
ViewBag.pageTitle = "Edit Document Types";
Layout = "~/Views/Shared/_Layout.cshtml";
}
- Layout: Reuses the site-wide layout.
- ViewBag keys feed into the header and breadcrumbs.
🏗 Form Structure & HTML Elements
<h2>Update Document Type</h2>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="EditDocType">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<!-- Hidden Fields -->
<input type="hidden" asp-for="Id" />
<input type="hidden" asp-for="Type" />
<!-- Read‑only Type -->
<div class="form-group">
<label asp-for="Type"></label>
<input type="text"
value="@Model.Type"
class="form-control"
readonly />
<span asp-validation-for="Type"></span>
</div>
<!-- Description -->
<div class="form-group">
<label asp-for="Description"></label>
<input asp-for="Description" class="form-control" />
<span asp-validation-for="Description"></span>
</div>
<!-- Category Dropdown (Syncfusion) -->
<div class="form-group row mb-2">
<label class="col-sm-2">Document Categories</label>
<div class="col-sm-12">
<ejs-dropdownlist
id="Category"
dataSource="@ViewBag.type"
value="@Model.Category"
placeholder="Select document categories"
width="600px">
</ejs-dropdownlist>
</div>
</div>
<!-- Index Types MultiSelect (Syncfusion) -->
<div class="form-group row mb-2">
<label class="col-sm-2">Index Types</label>
<div class="col-sm-12">
<ejs-multiselect
id="indexType"
placeholder="Select Index types"
mode="CheckBox"
allowFiltering="true"
filtering="onfiltering"
actionBegin="onBegin"
dataBound="onBound"
popupHeight="200px"
width="900px"
dataSource="@ViewBag.indexes">
<e-multiselect-fields text="Type" value="Id"></e-multiselect-fields>
</ejs-multiselect>
</div>
</div>
<!-- Flags -->
<div class="form-group">
<label asp-for="IsAvailable"></label>
<input asp-for="IsAvailable" type="checkbox" />
</div>
<div class="form-group">
<label asp-for="IsDeleted"></label>
<input asp-for="IsDeleted" type="checkbox" />
</div>
<!-- Actions -->
<div class="form-group">
<a asp-action="DocumentTypes"
asp-controller="HRImaging"
class="btn btn-danger irby-red">Back to List</a>
<input type="submit"
value="Update"
class="btn btn-success irby-green" />
</div>
</form>
</div>
</div>
🔌 Third‑Party Components
| Component | Purpose |
|---|---|
<ejs-dropdownlist> |
Single-select dropdown for Categories |
<ejs-multiselect> |
Multi-select with checkboxes for Index Types |
- Filtering:
allowFiltering="true"+onfilteringcallback - Selection Persistence: Custom JS (
onBegin,onBound) captures pre-selected items.
🛠 JavaScript Helpers & Utilities
<script>
// Holds selected IndexType IDs
var selected = [];
// Called when multiselect begins loading items
function onBegin(e) {
this.fields = {
text: 'Type',
value: 'Id',
itemCreated: function (args) {
if (args.curData.IsSelected) {
// Keep track of pre-selected IDs
itemSearch(args.curData.Id);
}
}
};
}
// Add to selected array if not exists
function itemSearch(id) {
if (selected.indexOf(id) === -1) {
selected.push(id);
}
}
// After data bound, set the multiselect value
function onBound(e) {
this.value = selected;
}
// Filtering logic for IndexTypes
function onfiltering(e) {
var query = new ej.data.Query();
query = (e.text !== '')
? query.where('Type', 'startswith', e.text, true)
: query;
e.updateData(
@Html.Raw(JsonConvert.SerializeObject(ViewBag.data)),
query
);
}
// Enable Syncfusion ripple & input-focus effect
ej.base.enableRipple(true);
var inputs = document.querySelectorAll('.e-input-group .e-input, .e-float-input.e-input-group input');
inputs.forEach(i => {
i.addEventListener('focus', () => i.parentNode.classList.add('e-input-focus'));
i.addEventListener('blur', () => i.parentNode.classList.remove('e-input-focus'));
});
</script>
🛡 Error Handling & Validation
-
Server‑Side:
- Data Annotations on
DocumentTypeView(e.g.[Required]) <div asp-validation-summary="ModelOnly" class="text-danger"></div><span asp-validation-for="…"></span>for field-level messages
- Data Annotations on
-
Client‑Side:
- Syncfusion controls provide built-in validation styling.
- HTML5
requiredattribute on read‑onlyTypeinput (for consistency).
🔄 Controller Interaction & Endpoints
- Form POST →
HRImagingController.EditDocType(DocumentTypeView model) - Back to List →
HRImagingController.DocumentTypes()
[HttpPost]
public IActionResult EditDocType(DocumentTypeView model) {
if (!ModelState.IsValid) {
// repopulate ViewBag.type, ViewBag.indexes, etc.
return View(model);
}
// Update logic...
return RedirectToAction(nameof(DocumentTypes));
}
🎯 Sample Usage
-
Populate ViewBag in the Controller:
ViewBag.type = GetDocumentCategories(); // List<SelectListItem> ViewBag.indexes = GetIndexTypes(); // List<IndexTypeDto> ViewBag.data = ViewBag.indexes; // for filtering -
Navigate to
/HRImaging/EditType/{id} -
Edit fields, select/unselect index types, and Submit.
📌 The multi-select will preserve pre-selected items and allow dynamic filtering.
🗺 UML Diagram of Data Model
classDiagram
class DocumentTypeView {
+int Id
+string Type
+string Description
+int Category
+List~int~ IndexTypes
+bool IsAvailable
+bool IsDeleted
}
🏁 Conclusion
The EditType.cshtml Razor view offers a clean, interactive interface to update document types within HR Imaging. By combining ASP.NET Core MVC with Syncfusion EJ2 controls, it provides:
- Robust form validation
- Rich dropdown and multiselect experiences
- Strongly‑typed data binding via
DocumentTypeView - Flexible filtering and state preservation through custom JS handlers
This documentation should help you understand, maintain, and extend the Edit Document Type functionality with confidence. Happy coding! 🚀