📄 Documentation: EditCategory.cshtml
📋 Table of Contents
- Introduction
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- Models & View Models
- Helper Methods & Utilities
- Error Handling & Validation
- API Endpoints Overview
- Third‑party Integrations
- Sample Code Blocks & Usage Examples
- UML Sequence Diagram
- Conclusion
1. Introduction
Welcome to the detailed documentation for the Razor View EditCategory.cshtml under the IrbyImaging/Views/LegalImaging folder. 🖥️ This document will walk you through the purpose, functionality, data flow, and usage examples for this view, which is part of the LegalImaging area in an ASP.NET Core MVC application.
2. Overview & Purpose
EditCategory.cshtml is a Razor view designed to update an existing document category (e.g., legal, safety, IT) in the system. It renders a form pre-populated with the selected category’s details (Name, Description, Availability, Deletion flag) and allows the user to apply changes.
Key objectives:
- Display the current values of a document category.
- Perform model binding and server-side validation.
- Submit updates back to the
LegalImagingController.
3. Key Functional Areas
| Section | Description |
|---|---|
| ViewBag Setup | Sets page titles and layout. |
| Category Type Resolution | Determines “legal” / “safety” / “it” for routing and labels based on ImagingType |
| Form Rendering | Renders form fields for Name, Description, IsAvailable, IsDeleted |
| Hidden Fields Management | Maintains Id, ImagingType, IsLegal, IsSafety, IsIT for round‑trip data |
| Navigation Buttons | “Back to List” link & “Update” button |
| Client-Side Scripts | Includes Bootstrap, MetisMenu, SimpleBar, Waves for UI enhancements |
4. Dependencies & Technologies
- ASP.NET Core MVC
- Razor View Engine
- Syncfusion EJ2 (
@using Syncfusion.JavaScript,@using Syncfusion.JavaScript.Models) - Bootstrap for styling and responsive layout
- MetisMenu, SimpleBar, Node‑Waves for UI widgets
5. Models & View Models
DocumentCategoryView
The view is strongly typed to IrbyImaging.UI.Models.DocumentCategoryView.
Below is a simplified representation:
public class DocumentCategoryView
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsAvailable { get; set; }
public bool IsDeleted { get; set; }
public ImagingType ImagingType { get; set; }
public bool IsLegal { get; set; }
public bool IsSafety { get; set; }
public bool IsIT { get; set; }
}
public enum ImagingType
{
Legal,
Safety,
IT
}
Fields in the form
| Field | Type | Purpose |
|---|---|---|
Name |
string |
Category name (read‑only) |
Description |
string |
Editable description |
IsAvailable |
bool |
Toggle availability |
IsDeleted |
bool |
Soft‑delete toggle |
| Hidden fields | various | Track Id, ImagingType, and flags |
6. Helper Methods & Utilities
Although this view does not define custom helpers, it leverages ASP.NET Core Tag Helpers and HTML Helpers:
asp-forasp-action,asp-route-...,asp-controllerHtml.HiddenFor(...),Html.ValidationSummary(...),Html.ValidationFor(...)
These automatically bind model properties, generate appropriate name & id attributes, and wire up validation.
7. Error Handling & Validation
- Server-Side Validation
[Required],[StringLength], etc., on theDocumentCategoryViewmodel.- Errors surfaced via
asp-validation-summary="ModelOnly"andasp-validation-for.
- Client-Side Validation
- Enabled by default in ASP.NET Core (jQuery Unobtrusive).
- Input fields carry
data-val-*attributes.
8. API Endpoints Overview
GET: /LegalImaging/EditDocCategory/{id}
- Fetches the category by
idand returnsEditCategory.cshtml.
POST: /LegalImaging/EditDocCategory
- Receives the bound
DocumentCategoryView. - Validates & updates the category in the database.
- On success, redirects to
/LegalImaging/DocumentCategories?category={legal|safety|it}.
| Action | Route | Method | Model |
|---|---|---|---|
| Edit Document Category (POST) | /LegalImaging/EditDocCategory |
POST | DocumentCategoryView |
9. Third‑party Integrations
- Syncfusion EJ2
- Namespaces imported but not currently utilized in this view—likely for a future grid or drop-down.
- UI Libraries
- Bootstrap for layout
- MetisMenu, SimpleBar, Node‑Waves included for consistent site navigation and effects.
10. Sample Code Blocks & Usage Examples
Full Razor View
@model IrbyImaging.UI.Models.DocumentCategoryView
@using Syncfusion.JavaScript
@using Syncfusion.JavaScript.Models
@using Syncfusion.EJ2
@{
ViewBag.Title = "Edit Document Category";
Layout = "~/Views/Shared/_LegalLayout.cshtml";
// Determine route segment based on ImagingType
var category = Model.ImagingType switch
{
IrbyImaging.DomainClasses.ImagingType.Legal => "legal",
IrbyImaging.DomainClasses.ImagingType.Safety => "safety",
IrbyImaging.DomainClasses.ImagingType.IT => "it",
_ => ""
};
}
<h2>Update Document Type</h2>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="EditDocCategory">
@* Hidden metadata *@
@Html.HiddenFor(m => m.Id)
@Html.HiddenFor(m => m.ImagingType)
@Html.HiddenFor(m => m.IsLegal)
@Html.HiddenFor(m => m.IsSafety)
@Html.HiddenFor(m => m.IsIT)
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" required readonly />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<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>
<div class="form-group">
<label asp-for="IsAvailable" class="control-label"></label>
<input asp-for="IsAvailable" type="checkbox" />
<span asp-validation-for="IsAvailable" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="IsDeleted" class="control-label"></label>
<input asp-for="IsDeleted" type="checkbox" />
<span asp-validation-for="IsDeleted" class="text-danger"></span>
</div>
<div class="form-group">
<a asp-action="DocumentCategories"
asp-controller="LegalImaging"
asp-route-category="@category"
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>
<!-- 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>
11. UML Sequence Diagram
sequenceDiagram
participant User as 👤 End User
participant View as 🖥️ EditCategory.cshtml
participant Ctrl as ⚙️ LegalImagingController
participant Svc as 🔧 Service Layer
participant DB as 🗄️ Database
User->>Ctrl: GET /LegalImaging/EditDocCategory/5
Ctrl->>Svc: GetCategoryById(5)
Svc->>DB: SELECT * FROM Categories WHERE Id=5
DB-->>Svc: Category data
Svc-->>Ctrl: return CategoryViewModel
Ctrl-->>View: Render EditCategory.cshtml(Model)
User->>View: Fills form and submits
View->>Ctrl: POST /EditDocCategory (DocumentCategoryView)
Ctrl->>Svc: UpdateCategory(ViewModel)
Svc->>DB: UPDATE Categories SET ...
DB-->>Svc: Success
Svc-->>Ctrl: Success
Ctrl->>User: Redirect to /DocumentCategories?category=legal
12. Conclusion
EditCategory.cshtml is a focused Razor view for editing document categories within the Legal Imaging module.
Key takeaways:
- Leverages ASP.NET Core Tag Helpers for clean markup & binding.
- Respects different
ImagingTypecontexts (legal, safety, IT). - Provides built‑in validation feedback.
- Integrates seamlessly with controller actions and service layers.
Feel free to extend this view with additional Syncfusion controls (grids, dropdowns) or custom JavaScript for richer UX. 🥳