π Create Document Category View (CreateCategory.cshtml)
π Table of Contents
- Overview & Purpose
- File Location & Structure
- Dependencies & Technologies
- View Model
- Layout & Page Settings
- UI Structure
- 6.1 Header & Title
- 6.2 Form Elements
- 6.2.1 Validation Summary
- 6.2.2 Name Field
- 6.2.3 Description Field
- 6.2.4 Action Buttons
- Client-Side Scripts
- Usage Example
- Sequence Diagram (UML)
- Conclusion
1. Overview & Purpose π
The CreateCategory.cshtml view provides a user interface for creating a new Document Category within the HR Imaging module of the IrbyImaging application. It renders a form that accepts the category Name and Description, performs client-side and server-side validation, and posts the data to the CreateDocCategory action in the HRImaging controller.
2. File Location & Structure ποΈ
IrbyImaging/
ββ Views/
β ββ HRImaging/
β β ββ CreateCategory.cshtml β This file
β ββ Shared/
β ββ _Layout.cshtml
3. Dependencies & Technologies π§
| Technology / Library | Purpose |
|---|---|
| ASP.NET Core MVC Razor | Serverβside view templating |
Tag Helpers (asp-for, asp-action) |
Model binding & URL generation |
| Syncfusion.EJ2 JavaScript | (Imported, not used in this view) |
| Bootstrap 5 | Layout, grid system & components |
| MetisMenu, SimpleBar, Waves | Secondary UI enhancement scripts |
Note: Syncfusion namespaces are included (
@using Syncfusion.JavaScript) but not actively used in this particular view.
4. View Model π§©
@model IrbyImaging.UI.Models.DocumentCategoryView
- DocumentCategoryView
string Namestring Description- (Potentially additional metadata for validation)
This model drives form fields and validation messages.
5. Layout & Page Settings ποΈ
@{
ViewBag.Title = "Create Document Category";
ViewBag.pTitle = "Create Document Category";
ViewBag.pageTitle = "Create Document Category";
Layout = "~/Views/Shared/_Layout.cshtml";
}
- Layout: Inherits common UI (header, footer, navigation) from
_Layout.cshtml. - ViewBag: Sets page metadata (useful for breadcrumbs, page headers, SEO).
6. UI Structure π¨
6.1 Header & Title
<h2>Create Document Category</h2>
<hr />
<h2>: Page-level heading<hr />: Visual separator
6.2 Form Elements
<form asp-action="CreateDocCategory">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<!-- Name Field -->
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<!-- Description Field -->
<div class="form-group">
<label asp-for="Description" class="control-label"></label>
<input asp-for="Description" class="form-control" />
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<br />
<!-- Action Buttons -->
<div class="form-group">
<a asp-action="DocumentCategories" asp-controller="HRImaging"
class="btn btn-danger irby-red">Back to List</a>
<input type="submit" value="Create" class="btn btn-success irby-green" />
</div>
</form>
6.2.1 Validation Summary
- Summarizes model-level errors
- Rendered by
<div asp-validation-summary="ModelOnly">
6.2.2 Name Field
| Element | Purpose |
|---|---|
<label asp-for="Name"> |
Renders <label for="Name"> |
<input asp-for="Name"> |
Two-way binds Model.Name |
<span asp-validation-for="Name"> |
Displays name-specific error |
6.2.3 Description Field
Similar pattern to Name Field, binds Model.Description.
6.2.4 Action Buttons
- Back to List:
asp-action="DocumentCategories"asp-controller="HRImaging"- Styled as a red Bootstrap button
- Create:
- Submits the form to
CreateDocCategory - Styled as a green Bootstrap button
- Submits the form to
7. Client-Side Scripts π
<script src="~/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/libs/metismenu/metisMenu.min.js"></script>
<script src="~/libs/simplebar/simplebar.min.js"></script>
<script src="~/libs/node-waves/waves.min.js"></script>
- Bootstrap: Tooltips, modals, responsive behavior
- MetisMenu: Side menu interactions
- SimpleBar: Custom scrollbars
- Waves: Ripple effects on buttons
8. Usage Example π οΈ
Controller Snippet
public class HRImagingController : Controller
{
// GET: Show empty form
public IActionResult CreateCategory()
{
return View("CreateCategory", new DocumentCategoryView());
}
// POST: Handle form submission
[HttpPost]
public async Task<IActionResult> CreateDocCategory(DocumentCategoryView model)
{
if (!ModelState.IsValid)
return View("CreateCategory", model);
// TODO: Persist category
await _categoryService.AddAsync(model);
return RedirectToAction("DocumentCategories");
}
}
9. Sequence Diagram (UML) π
@startuml
actor User
participant "CreateCategory.cshtml" as View
participant "HRImagingController" as Ctrl
participant "CategoryService" as Service
User -> View: Click "Create" button
View -> Ctrl: HTTP POST /HRImaging/CreateDocCategory
Ctrl -> Ctrl: Model binding & validation
alt Model valid
Ctrl -> Service: AddAsync(model)
Service --> Ctrl: Success
Ctrl -> User: Redirect to /HRImaging/DocumentCategories
else Model invalid
Ctrl -> View: Return View(model) with errors
View --> User: Display validation messages
end
@enduml
10. Conclusion π
This view is a simple, clean, and consistent Razor page for creating document categories in the HR Imaging module. It leverages ASP.NET Core MVC featuresβlike Tag Helpers and Model Validationβto deliver a robust user experience. By adhering to shared layouts and styling conventions, it ensures UI consistency within the IrbyImaging application.
Feel free to extend this template with additional fields (e.g., category parent, icons) or clientβside enhancements (e.g., realβtime validation, rich text editors) as requirements evolve.