📄 Create Document Category View (CreateCategory.cshtml)


📚 Table of Contents

  1. 🔎 Overview & Purpose
  2. 🗂 File Path & Location
  3. ⚙️ Dependencies & Technologies
  4. 🧩 View Model
  5. 🎨 Layout & Page Titles
  6. 🛠 Form Structure & Functional Areas
  7. 🔗 API Endpoint & Routing
  8. 📦 Client-side Scripts & Integrations
  9. 🌐 UML Sequence Diagram
  10. 🚀 Usage Example
  11. ✅ Conclusion

🔎 Overview & Purpose

This Razor View renders a form to create a new Document Category within the Legal Imaging area of the application. It guides users through entering the category’s Name and Description, preserving contextual flags (Legal, Safety, IT, ImagingType) via hidden fields, and posts the data back to the controller for processing.

“Create Document Category” is the landing page for admins/business users to add new organizational categories for document management under legal workflows.


🗂 File Path & Location

IrbyImaging
 └── Views
     └── LegalImaging
         └── CreateCategory.cshtml

⚙️ Dependencies & Technologies

Technology / Library Purpose
ASP.NET Core MVC / Razor Views Server‑side rendering with Tag Helpers
Tag Helpers (asp-for, etc.) Strongly‑typed binding between view & model
Syncfusion JavaScript UI components (loaded via @using Syncfusion.*)
Bootstrap (bundle) Responsive layout & form styling
MetisMenu Sidebar menu behavior
SimpleBar Custom scrollbars
Waves.js Click effect for UI elements

😎 Fun Fact: The view uses HTML Helpers (@Html.HiddenFor) alongside Tag Helpers (<input asp-for="..." />) interchangeably.


🧩 View Model

This view is strongly typed to the DocumentCategoryView model.

@model IrbyImaging.UI.Models.DocumentCategoryView

DocumentCategoryView Properties

Property Type Description
Name string (Required) The display name of the category.
Description string A brief description or notes about this category.
ImagingType string Category grouping (e.g., “Legal”, “Safety”, “IT”).
IsLegal bool Flag: whether this category applies to legal imaging.
IsSafety bool Flag: whether this category applies to safety imaging.
IsIT bool Flag: whether this category applies to IT imaging.

🔧 Note: Hidden fields ensure these flags persist post‑back without user manipulation.


🎨 Layout & Page Titles

@{
    ViewBag.Title     = "Create Document Category";
    ViewBag.pTitle    = "Create Document Category";
    ViewBag.pageTitle = "Create Document Category";
    Layout            = "~/Views/Shared/_LegalLayout.cshtml";
}
  • Layout: reuses a shared layout with navigation/menu specific to the Legal Imaging section.
  • ViewBag.*: sets browser tab title, page header, and breadcrumb title.

🛠 Form Structure & Functional Areas

<h2>Create Document Category</h2>
<hr />
<div class="row">
  <div class="col-md-4">
    <form asp-action="CreateDocCategory">
      <!-- Hidden Context Flags -->
      @Html.HiddenFor(m => m.ImagingType)
      @Html.HiddenFor(m => m.IsLegal)
      @Html.HiddenFor(m => m.IsSafety)
      @Html.HiddenFor(m => m.IsIT)

      <!-- Validation Summary -->
      <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">
        @* Preserve hidden flags again to ensure binding *@
        @Html.HiddenFor(m => m.ImagingType)
        @Html.HiddenFor(m => m.IsLegal)
        @Html.HiddenFor(m => m.IsSafety)
        @Html.HiddenFor(m => m.IsIT)

        <a asp-controller="LegalImaging"
           asp-action="DocumentCategories"
           asp-route-category="@ViewBag.category"
           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>
  </div>
</div>
<br /><br />

Key Functional Areas

  1. Hidden Fields: Persist context flags without user interaction.
  2. Validation:
    • asp-validation-summary="ModelOnly" shows all model errors.
    • asp-validation-for for per-field error messages.
  3. Data Inputs:
    • Name (required)
    • Description (optional)
  4. Navigation Buttons:
    • Back to List returns to the category index.
    • Create submits the form to the server.

🔗 API Endpoint & Routing

  • Form Action: asp-action="CreateDocCategory"
  • Controller: implicitly LegalImagingController (same folder)
  • HTTP Method: POST
[HttpPost]
public IActionResult CreateDocCategory(DocumentCategoryView model)
{
    if (!ModelState.IsValid)
    {
        return View("CreateCategory", model);
    }
    // ... persist to database, redirect ...
}
Endpoint Method Description
/LegalImaging/CreateDocCategory POST Processes creation of a new category.

📦 Client-side Scripts & Integrations

<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: responsive grid, button styling.
  • MetisMenu: collapsible sidebar menus.
  • SimpleBar: custom scrollbars for consistent UI.
  • Waves.js: material-inspired click ripple effects.

⚠️ Note: No direct Syncfusion components are leveraged in the markup, but the @using Syncfusion.* directives are prepared for potential grid or dropdown enhancements.


🌐 UML Sequence Diagram

Below is a simplified sequence diagram illustrating the flow from user interaction to server-side processing:

sequenceDiagram
    participant User
    participant View as CreateCategory.cshtml
    participant Ctrl as LegalImagingController
    participant Model as DocumentCategoryView

    User->>View: Opens “Create Document Category”
    View-->>User: Renders Form (Name, Description, Hidden Flags)
    User->>View: Fills form & clicks “Create”
    View->>Ctrl: POST CreateDocCategory(model)
    Ctrl->>Ctrl: Validate ModelState
    alt Validation Fails
        Ctrl->>View: return View("CreateCategory", model)
    else Validation Succeeds
        Ctrl->>Model: Save to database
        Ctrl->>User: Redirect to “DocumentCategories” list
    end

🚀 Usage Example

1. Controller Action (GET)

public IActionResult CreateCategory()
{
    var model = new DocumentCategoryView {
        ImagingType = "Legal",
        IsLegal     = true,
        IsSafety    = false,
        IsIT        = false
    };
    return View("CreateCategory", model);
}

2. User Interaction

  1. Navigate to /LegalImaging/CreateCategory
  2. Fill out Name & Description
  3. Click Create
  4. On success, you’ll be redirected to the Document Categories listing page.

✅ Conclusion

The CreateCategory.cshtml view is a focused, user‑friendly interface for adding new document categories in the Legal Imaging module. Leveraging ASP.NET Core Tag Helpers, Model Binding, and Client‑side Validation, it ensures data integrity and a consistent UX. With hidden context flags and robust layout integration, it seamlessly ties into the broader document management workflow.

Feel free to extend this view with additional Syncfusion components (e.g., dropdown lists, grids) for richer interactions!


⭐️ Happy coding and thank you for using IrbyImaging!