πŸ“„ CreateType.cshtml Documentation

Welcome to the comprehensive documentation for IrbyImaging/Views/HRImaging/CreateType.cshtml! This file defines the Razor view for creating a new Document Type in the HR Imaging module. Below you’ll find everything you need to understand its purpose, structure, dependencies, usage, and how it ties into the rest of the application.


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Models
  4. Key Functional Areas
  5. Form Structure & Tag Helpers
  6. Syncfusion Components
  7. Error Handling & Validation
  8. Scripts & Layout
  9. Usage Example (Controller Snippet)
  10. UML Sequence Diagram & Flow
  11. Conclusion

1. Overview & Purpose

:mag: What is CreateType.cshtml?
This Razor view (.cshtml) renders a web form that allows HR administrators to create and configure new Document Types. A Document Type consists of:

  • A Name (Type)
  • A Description
  • A single Document Category
  • One or more Index Types

When the form is submitted, it posts data back to the HRImagingController’s CreateDocType action to persist the new Document Type.


2. Dependencies & Technologies

Technology Purpose
ASP.NET Core MVC Server-side framework & Razor view engine
Tag Helpers asp-for, asp-action, asp-validation-for
Syncfusion EJ2 Controls <ejs-dropdownlist>, <ejs-multiselect>
Bootstrap 5 Responsive layout & styling
MetisMenu, SimpleBar, Waves UI enhancements (sidebar, scrollbars, ripple)
jQuery (implicit) Required by Syncfusion JavaScript components

3. View Model & Data Models

DocumentTypeView (Model)

Property Type Description
Type string Name of the Document Type
Description string Detailed description
CategoryId int Selected Category (via dropdown)
IndexTypeIds int[] Array of selected Index Type IDs

Note: The actual C# class may contain DataAnnotations for validation (e.g., [Required], [StringLength]).

public class DocumentTypeView
{
    [Required, Display(Name = "Type")]
    public string Type { get; set; }

    [Display(Name = "Description")]
    public string Description { get; set; }

    [Required]
    public int CategoryId { get; set; }

    public int[] IndexTypeIds { get; set; }
}

4. Key Functional Areas

  1. Page Setup & Layout

    • Sets ViewBag titles for rendering in _Layout.cshtml
    • Declares the page’s main <h2> header
  2. Form Section

    • Uses asp-action="CreateDocType" to target the POST action
    • Contains fields for Type, Description, Category, and Index Types
  3. Syncfusion Components

    • <ejs-dropdownlist> for Category selection
    • <ejs-multiselect> for choosing multiple Index Types
  4. Navigation Buttons

    • Back to List: Anchor to DocumentTypes action
    • Create: Submits the form

5. Form Structure & Tag Helpers

<form asp-action="CreateDocType">
  <div asp-validation-summary="ModelOnly" class="text-danger"></div>

  <!-- Document Type Name -->
  <div class="form-group">
    <label asp-for="Type" class="control-label"></label>
    <input asp-for="Type" class="form-control"/>
    <span asp-validation-for="Type" class="text-danger"></span>
  </div>

  <!-- Description -->
  <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>

  <!-- Document Categories -->
  <!-- See Syncfusion dropdown in next section -->

  <!-- Index Types -->
  <!-- See Syncfusion multiselect in next section -->

  <!-- Buttons -->
  <div class="form-group">
    <a asp-action="DocumentTypes" 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>
  • asp-for binds to the model property
  • asp-validation-for displays per-field validation messages
  • asp-validation-summary shows model-level errors

6. Syncfusion Components

6.1 Category Dropdown

<ejs-dropdownlist 
  id="Category" 
  width="900px"
  placeholder="Select document category"
  popupHeight="200px"
  dataSource="@ViewBag.data">
  <e-dropdownlist-fields 
    groupBy="Category" 
    text="Type" 
    value="Id">
  </e-dropdownlist-fields>
</ejs-dropdownlist>
  • dataSource: Populated in Controller via ViewBag.data (list of categories)
  • text: Display text field (Type)
  • value: Underlying value (Id)
  • groupBy: Optional grouping by another field (Category)

6.2 Index Types Multiselect

<ejs-multiselect
  id="indexType"
  width="900px"
  placeholder="Index types"
  mode="CheckBox"
  popupHeight="200px"
  dataSource="@ViewBag.indexes">
  <e-multiselect-fields 
    text="Type" 
    value="Id">
  </e-multiselect-fields>
</ejs-multiselect>
  • mode="CheckBox" displays checkboxes in the dropdown
  • dataSource: Supplied from ViewBag.indexes

7. Error Handling & Validation

  • The view leverages Server-side model validation:
    • [Required] / [StringLength] in DocumentTypeView
    • asp-validation-summary & asp-validation-for display errors
  • On invalid submit, the same view is re-rendered with validation messages

8. Scripts & Layout

@{
  Layout = "~/Views/Shared/_Layout.cshtml";
  ViewBag.Title   = "Create Document Type";
  ViewBag.pTitle  = "Create Document Types";
  ViewBag.pageTitle = "Create Document Types";
}

<!-- ... form markup ... -->

<!-- JS Dependencies -->
<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>
  • Layout: Uses a shared template (_Layout.cshtml) for consistent header/sidebar
  • Scripts: Loaded at the bottom to optimize page load

9. Usage Example (Controller Snippet)

public class HRImagingController : Controller
{
    // Display the Create form
    public IActionResult CreateType()
    {
        ViewBag.data    = _categoryService.GetDocumentCategories();
        ViewBag.indexes = _indexService.GetIndexTypes();
        return View();
    }

    // Handle POST
    [HttpPost]
    public IActionResult CreateDocType(DocumentTypeView model)
    {
        if (!ModelState.IsValid)
        {
            // Re-populate dropdowns on error
            ViewBag.data    = _categoryService.GetDocumentCategories();
            ViewBag.indexes = _indexService.GetIndexTypes();
            return View("CreateType", model);
        }

        // Save to database...
        _docTypeService.AddNew(model);

        // Redirect to the list page
        return RedirectToAction("DocumentTypes");
    }
}

10. UML Sequence Diagram & Flow

sequenceDiagram
    participant User
    participant View as CreateType.cshtml
    participant Ctlr as HRImagingController
    participant Service as DocumentTypeService
    participant DB as Database

    User->>Ctlr: GET /HRImaging/CreateType
    Ctlr->>Service: GetDocumentCategories(), GetIndexTypes()
    Service-->>Ctlr: Lists
    Ctlr-->>View: View(Model + ViewBag)
    View->>User: Render Form

    User->>View: Fill & Submit Form
    View->>Ctlr: POST CreateDocType(model)
    Ctlr->>Service: AddNew(model)
    Service->>DB: INSERT DocumentType + Links
    DB-->>Service: Success
    Service-->>Ctlr: Confirmation
    Ctlr-->>User: Redirect /HRImaging/DocumentTypes

11. Conclusion

πŸŽ‰ You’re all set! This view empowers HR administrators to define new Document Types with rich UI controls from Syncfusion, integrated seamlessly into ASP.NET Core MVC. Remember to:

  • Supply ViewBag.data and ViewBag.indexes in your controller
  • Apply proper model validation attributes
  • Keep your shared layout and scripts up to date

Feel free to extend this view (e.g., add more fields or client-side validation) as your application evolves. Happy coding! πŸš€