📄 CreateAttribute.cshtml Documentation
📑 Table of Contents
- Overview & Purpose
- Technologies & Dependencies
- View Model & Data Model
- UI Components & Key Functional Areas
- Form Submission & API Endpoint
- Error Handling & Validation
- Third‐Party Integrations
- Sample Usage & Code Snippets
- UML Diagram
- Conclusion
🧐 Overview & Purpose
CreateAttribute.cshtml is an ASP.NET MVC Razor View under IrbyImaging/Views/HRImaging. It renders a form for creating new “Attribute Types” used in the HR Imaging module.
- Users can define:
- A unique Index Name
- Its Data Type (string, number, date, etc.)
- Whether it supports multiple values
- A comma‐separated list of allowed values
- Flags like Is Required, Link Employee Data, Link Job Data
- Assign the attribute to one or more Document Types
This enhances the system’s flexibility by letting administrators configure custom metadata for documents.
🛠️ Technologies & Dependencies
| Technology / Library | Purpose |
|---|---|
| ASP.NET Core MVC / Razor | Server‑side view rendering |
| Bootstrap 4 / CSS Grid | Responsive layout & styling |
| Syncfusion EJ2 JavaScript | Rich UI components (Dropdown, MaskEdit, etc.) |
| Newtonsoft.Json | JSON serialization (if needed in ViewBag) |
Tag Helpers (asp-action) |
Simplify form creation & routing |
🎯 View Model & Data Model
@model IrbyImaging.UI.Models.DocumentAttributeView
DocumentAttributeView (simplified) might include:
| Property | Type | Description |
|---|---|---|
| AttributeName | string | The name/key of the attribute |
| DataType | string | Data type (e.g., Text, Number, Date) |
| MultiValue | bool | Allows multiple selections? |
| Values | string | Comma‐separated allowed values |
| IsRequired | bool | Is this field mandatory? |
| LinkEmployeeData | bool | Link attribute to employee record? |
| LinkJobData | bool | Link attribute to job record? |
| DocumentTypes | List | IDs of associated document types |
Note: The actual model may have validation attributes (
[Required],[StringLength], etc.).
📐 UI Components & Key Functional Areas
Below is a breakdown of each UI component within the form:
1. Attribute Name Input
<ej-mask-edit
width="400px"
id="attributeName"
input-mode="@InputMode.Text"
watermark-text="Enter Attribute Name">
</ej-mask-edit>
- Control: Syncfusion MaskEdit
- Purpose: Capture the unique name of the attribute.
- Binding:
DocumentAttributeView.AttributeName
2. Data Type Selection
<ejs-dropdownlist
width="400px"
id="datatype"
dataSource="@ViewBag.datatype"
popupWidth="300px"
placeholder="Select data type"
popupHeight="220px">
</ejs-dropdownlist>
- Control: Syncfusion DropDownList
- Data: Fed via
ViewBag.datatype(e.g.,new[] { "Text", "Number", "Date" }) - Binding:
DocumentAttributeView.DataType
3. Multi‑Value Configuration
<ejs-checkbox
id="multivalue"
name="multivalue"
label="MultiValue">
</ejs-checkbox>
- Control: Syncfusion CheckBox
- Purpose: Enable selection of multiple values for this attribute.
- Binding:
DocumentAttributeView.MultiValue
4. Index Values Input
<textarea
class="form-control"
id="values"
name="values"
placeholder="Enter comma separated values for Multi Select...">
</textarea>
- Control: HTML
<textarea> - Purpose: Define allowed values (only relevant if MultiValue = true).
- Binding:
DocumentAttributeView.Values
5. Required & Link Flags
| UI Element | Description | Property Binding |
|---|---|---|
| Is Index Value Required | ejs-checkbox labelling IsRequired |
DocumentAttributeView.IsRequired |
| Link Employee Data? | ejs-checkbox labelling LinkEmployeeData |
DocumentAttributeView.LinkEmployeeData |
| Link Job Data? | ejs-checkbox labelling LinkJobData |
DocumentAttributeView.LinkJobData |
Example:
<ejs-checkbox id="isRequired" name="isRequired" label="IsRequired"></ejs-checkbox>
6. Document Types MultiSelect
<ejs-multiselect
width="600px"
id="doctype"
placeholder="document types"
mode="CheckBox"
popupHeight="200px"
dataSource="@ViewBag.data">
<e-multiselect-fields
groupBy="Category"
text="Type"
value="Id">
</e-multiselect-fields>
</ejs-multiselect>
- Control: Syncfusion MultiSelect (with checkboxes)
- Data Source:
ViewBag.datacontaining{ Id, Type, Category } - Binding:
DocumentAttributeView.DocumentTypes
7. Form Actions (Buttons)
<a asp-action="DocumentAttributes"
asp-controller="HRImaging"
class="btn btn-danger irby-red">
Back to List
</a>
<input type="submit" value="Create" class="btn btn-success irby-green" />
- Back to List: Cancel & navigate back
- Create: Submit form to create a new attribute type
🚀 Form Submission & API Endpoint
<form asp-action="CreateAttributeType" method="post">
<!-- form fields… -->
</form>
- HTTP Method: POST
- Controller:
HRImagingController - Action:
CreateAttributeType(DocumentAttributeView model)
Typical Controller Signature:
[HttpPost]
public IActionResult CreateAttributeType(DocumentAttributeView model)
{
if (!ModelState.IsValid) {
// Repopulate ViewBag and redisplay form
return View(model);
}
// 1. Map ViewModel -> Domain Entity
// 2. Save to database
// 3. Redirect to DocumentAttributes list
return RedirectToAction("DocumentAttributes");
}
⚠️ Error Handling & Validation
- Client‑side: Syncfusion components provide basic input masking & required checks.
- Server‑side:
- ASP.NET ModelState validation
- If invalid, the form is re-rendered with validation messages.
- Enhancement:
- Add
[Required],[StringLength], or custom validation toDocumentAttributeView. - Display errors with
<span asp-validation-for="…" class="text-danger"></span>
- Add
🔗 Third‑Party Integrations
| Library | Usage |
|---|---|
| Syncfusion.EJ2 | Dropdowns, MaskEdit, CheckBoxes, MultiSelect controls |
| Newtonsoft.Json | (Optional) Serialization of complex objects in ViewBag |
Ensure the following NuGet packages are installed & scripts/styles are loaded in _Layout.cshtml:
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="XX.X.X" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
📋 Sample Usage & Code Snippets
1. Populating ViewBag in Controller
public IActionResult CreateAttributeType()
{
ViewBag.datatype = new[] { "Text", "Number", "Date", "Boolean" };
ViewBag.data = _documentService.GetAllTypes(); // returns List<{ Id, Type, Category }>
return View(new DocumentAttributeView());
}
2. Posting Data & Handling in Controller
[HttpPost]
public IActionResult CreateAttributeType(DocumentAttributeView model)
{
if (!ModelState.IsValid)
{
// reload dropdown & multiselect data
PopulateDropDowns();
return View(model);
}
_attributeService.Create(model);
return RedirectToAction("DocumentAttributes");
}
🏷️ UML Diagram
classDiagram
class DocumentAttributeView {
+string AttributeName
+string DataType
+bool MultiValue
+string Values
+bool IsRequired
+bool LinkEmployeeData
+bool LinkJobData
+List<int> DocumentTypes
}
class HRImagingController {
+IActionResult CreateAttributeType()
+IActionResult CreateAttributeType(DocumentAttributeView model)
+IActionResult DocumentAttributes()
}
DocumentAttributeView <-- HRImagingController : parameter
🎯 Conclusion
- CreateAttribute.cshtml provides a user-friendly interface to define custom document attributes in the HR Imaging system.
- Leveraging Syncfusion EJ2 controls ensures a polished UI/UX.
- The form is backed by a strongly‑typed ViewModel, with server‑side and client‑side validation.
- Proper separation of concerns:
- View handles UI
- Controller handles data and navigation
- Services/Repositories handle persistence
✨ With this setup, administrators can rapidly configure, extend, and manage document attributes—driving a highly configurable imaging solution!