πŸ“„ Create Document Category View (CreateCategory.cshtml)


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. File Location & Structure
  3. Dependencies & Technologies
  4. View Model
  5. Layout & Page Settings
  6. UI Structure
  7. Client-Side Scripts
  8. Usage Example
  9. Sequence Diagram (UML)
  10. 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 Name
    • string 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>
        &nbsp;&nbsp;
        <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

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.