📄 CreateCategory.cshtml Documentation
File Path:
IrbyImaging/Views/AccountingImaging/CreateCategory.cshtml
Purpose: Razor view for creating a new document category in the Accounting Imaging module.
📑 Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Model: DocumentCategoryView
- MVC Flow & UML Diagram
- Error Handling & Validation
- API Endpoints Overview
- Third‑party Integrations
- Usage Examples & Sample Code
- Conclusion
1. Overview & Purpose
This Razor view renders a form that allows users to create a new Document Category in the Accounting section of the Irby Imaging application. It:
- Presents input fields for Name and Description
- Manages multiple hidden flags (e.g.,
IsAccounting,IsLegal, etc.) - Submits data to the
CreateDocCategoryaction on theAccountingImagingController - Provides client‑side validation and navigation controls
2. Key Functional Areas
| Area | Description |
|---|---|
| Title & Header | Uses ViewBag to set page titles and <h2> for the heading. |
| Hidden Fields | Tracks ImagingType and boolean flags (IsLegal, IsSafety, IsIT, IsAccounting, IsBidding). |
| Validation Summary | Displays model-level errors via <div asp-validation-summary="ModelOnly">. |
| Input Fields | Two primary inputs with asp-for: |
NameDescription
Each has an associated<span asp-validation-for>for field‑level messages. | | Form Submission |- Back to List:
<a>navigates toDocumentCategorieson cancellation. - Create:
<input type="submit">to post data. | | Scripts Inclusion | Loads JS libraries (Bootstrap, MetisMenu, SimpleBar, Waves) at the bottom. |
3. Dependencies & Technologies
| Dependency / Technology | Purpose |
|---|---|
| ASP.NET Core MVC & Razor | Server‑side rendering, model binding & validation. |
Syncfusion JavaScript (@using) |
Potential UI components (not explicitly rendered here). |
| Bootstrap 5 | Styling & responsive grid (.row, .col-md-4, buttons). |
| MetisMenu, SimpleBar, Waves | Navigation & UI enhancements (script references). |
Tag Helpers (asp-for, asp-action) |
Simplifies form & element binding & routing. |
4. View Model: DocumentCategoryView
This view binds to the DocumentCategoryView model. While the full C# class isn’t shown here, it typically contains:
| Property | Type | Description |
|---|---|---|
| ImagingType | string | Category type indicator (e.g., “Accounting”). |
| IsLegal | bool | Flag for legal imaging. |
| IsSafety | bool | Flag for safety imaging. |
| IsIT | bool | Flag for IT imaging. |
| IsAccounting | bool | Flag for accounting imaging (true for this view). |
| IsBidding | bool | Flag for bidding imaging. |
| Name | string | Required. Name of the new category. |
| Description | string | Optional. Description of the category. |
Note: Hidden fields ensure that context (type & flags) persists across form submits.
5. MVC Flow & UML Diagram
flowchart LR
User[User] -->|GET /AccountingImaging/CreateCategory| Controller[AccountingImagingController]
Controller -->|Returns View(Model)| CreateView[(CreateCategory.cshtml)]
CreateView -->|Renders Form| Browser
Browser -->|POST /CreateDocCategory| Controller
Controller -->|Validates & Persists| Service[DocumentCategoryService]
Service -->|Success| Redirect[/AccountingImaging/DocumentCategories]
Service -->|Failure| CreateView
6. Error Handling & Validation
- Client‑side validation via unobtrusive validation attributes on
<input asp-for>. <div asp-validation-summary="ModelOnly">displays model errors not tied to a specific field.<span asp-validation-for>shows per-field error messages.
Typically, the CreateDocCategory action in the controller checks:
if (!ModelState.IsValid)
{
// Return same view with validation messages
return View(model);
}
7. API Endpoints Overview
| Action Name | HTTP Verb | Route | Purpose |
|---|---|---|---|
| CreateCategory | GET | /AccountingImaging/CreateCategory | Display the “Create” form. |
| CreateDocCategory | POST | /AccountingImaging/CreateDocCategory | Handle form submission & persist. |
| DocumentCategories | GET | /AccountingImaging/DocumentCategories | Redirect target after cancel/save. |
Route Params:
category(sent viaasp-route-category="@ViewBag.category"on Back link)
8. Third-party Integrations
-
Syncfusion JavaScript
Although no Syncfusion components are explicitly initialized here, the@usingdirectives suggest potential use of EJ2 controls elsewhere. -
Bootstrap
- Responsive grid
- Buttons (
.btn,.btn-success,.btn-danger)
-
MetisMenu, SimpleBar, Waves
- Enhances side‑navigation, custom scrollbars, and click ripple effects.
Scripts are referenced at the bottom:
<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>
9. Usage Examples & Sample Code
Rendering the View
// Controller: AccountingImagingController.cs
public IActionResult CreateCategory(string imagingType, bool isAccounting)
{
var model = new DocumentCategoryView
{
ImagingType = imagingType,
IsAccounting = isAccounting
// ... other flags
};
return View("CreateCategory", model);
}
Sample Form Data (HTTP POST)
POST /AccountingImaging/CreateDocCategory HTTP/1.1
Content-Type: application/x-www-form-urlencoded
ImagingType=Accounting
IsLegal=False
IsSafety=False
IsIT=False
IsAccounting=True
IsBidding=False
Name=Invoices
Description=All invoice related documents
10. Conclusion
🎯 The CreateCategory.cshtml view is a straightforward, form-based Razor page designed to capture new document category details for the Accounting module.
- It leverages ASP.NET Core MVC features for model binding, validation, and navigation.
- Hidden fields preserve context flags.
- Client‑side validation ensures a smooth user experience.
- Integration points with Bootstrap and other UI libraries deliver a responsive and consistent look & feel.
Feel free to extend this view with additional fields, Syncfusion components (e.g., dropdowns, date pickers), or JavaScript enhancements as your requirements grow. 🚀