📄 Edit Document Type View (EditType.cshtml)

Path: IrbyImaging/Views/AccountingImaging/EditType.cshtml


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Model & ViewModel
  4. Layout & Structure
  5. Key Functional Areas
  6. Error Handling & Validation
  7. UML Class Diagram
  8. Usage Examples
  9. Conclusion

1. Overview & Purpose

This Razor view enables editing an existing Document Type in the Accounting Imaging area of the IrbyImaging application. It:

  • Loads the current DocumentTypeView model (via @model)
  • Renders an editable form for Description, Category, Index Types, Availability and Deletion flags
  • Utilizes Syncfusion EJ2 controls for dropdown and multi‑select
  • Posts updates back to the EditDocType action

🎯 Use case: An administrator navigates to “Edit Document Type” to tweak metadata & indexing options for a given document category in the Accounting department.


2. Dependencies & Technologies

Category Technology / Package
View Engine ASP.NET Core Razor
Widgets & Controls Syncfusion EJ2 (ejs-dropdownlist, ejs-multiselect)
JSON Serialization Newtonsoft.Json
Client Utilities Bootstrap, MetisMenu, SimpleBar, Waves
Scripting Vanilla JS, Syncfusion JS API

3. Model & ViewModel

This view expects a DocumentTypeView model from IrbyImaging.UI.Models.
Below is a representative property table:

Property Type Description
Id int Primary key of the document type
Type string Immutable short code/name (read‑only)
Description string Editable description
Category int or enum Selected Category ID
Indexes IEnumerable<IndexType> Available index‑type options
IsAvailable bool Toggle for active/inactive
IsDeleted bool Soft-delete flag
ImagingType ImagingType enum Denotes Legal, Safety, IT, Accounting, Bidding
IsLegal bool View flag
IsSafety bool View flag
IsIT bool View flag
IsAccounting bool View flag
IsBidding bool View flag

4. Layout & Structure

@model IrbyImaging.UI.Models.DocumentTypeView
@using Syncfusion.JavaScript
@using Syncfusion.JavaScript.Models
@using Syncfusion.EJ2
@using Newtonsoft.Json

@{
  ViewBag.Title     = "Edit Document Type";
  ViewBag.pTitle    = "Edit Document Types";
  ViewBag.pageTitle = "Edit Document Types";

  // Determine the imagingType route segment dynamically
  var imagingType = Model.ImagingType.ToString().ToLower();  
}
<h2>Update Document Type</h2>
<hr/>
<div class="row">
  <div class="col-md-4">
    <form asp-action="EditDocType">
      <!-- Hidden and read‑only fields -->
      ...
    </form>
  </div>
</div>
<!-- Scripts: Bootstrap, Syncfusion, Custom JS -->
  • Top section injects namespaces & sets ViewBag
  • A dynamic imagingType string is computed for routing
  • The main form lives in a Bootstrap .row/.col-md-4

5. Key Functional Areas

5.1 Page Title & Routing Data

@{
  ViewBag.Title     = "Edit Document Type";
  ViewBag.pTitle    = "Edit Document Types";
  ViewBag.pageTitle = "Edit Document Types";
  var imagingType   = Model.ImagingType.ToString().ToLower();
}
  • ViewBag Titles drive <title> & page headers
  • imagingType chooses one of: legal, safety, it, accounting, bidding
  • Used for the “Back to List” link’s route segment

5.2 Razor Form & Validation

<form asp-action="EditDocType">
  @Html.HiddenFor(m => m.Id)
  <div asp-validation-summary="ModelOnly" class="text-danger"></div>
  <div class="form-group">
    <label asp-for="Type"></label>
    <input asp-for="Type" class="form-control" readonly />
    <span asp-validation-for="Type" class="text-danger"></span>
  </div>
  <!-- Description, checkboxes, etc. -->
</form>
  • Uses Tag Helpers:
    • asp-action to set form POST target
    • asp-for to bind inputs & labels
    • asp-validation-for & asp-validation-summary for client‑side errors

5.3 Syncfusion Controls

  1. Dropdown List for Document Categories
    <ejs-dropdownlist
      id="Category"
      dataSource="@ViewBag.type"
      value="@Model.Category"
      width="600px"
      placeholder="Select document categories"
      popupHeight="220px">
    </ejs-dropdownlist>
    
  2. MultiSelect with Checkboxes for Index Types
    <ejs-multiselect
      id="indexType"
      dataSource="@ViewBag.indexes"
      placeholder="Select Index types"
      mode="CheckBox"
      allowFiltering="true"
      dataBound="onBound"
      actionBegin="onBegin">
      <e-multiselect-fields text="Type" value="Id"></e-multiselect-fields>
    </ejs-multiselect>
    

5.4 Hidden Fields & Back‑Navigation

  • Hidden flags to preserve which imaging sections apply:
    @Html.HiddenFor(m => m.IsLegal)
    @Html.HiddenFor(m => m.IsSafety)
    <!-- ... -->
    
  • Back link to list view:
    <a asp-controller="LegalImaging"
       asp-action="DocumentTypes"
       asp-route-imagingType="@imagingType"
       class="btn btn-danger irby-red">
      Back to List
    </a>
    

5.5 JavaScript Helpers & Utilities

<script>
  var selected = [];

  function onBegin(e) {
    this.fields = {
      text: 'Type', value: 'Id',
      itemCreated: function(args) {
        if (args.curData.IsSelected) {
          itemSearch(args.curData.Id);
        }
      }
    };
  }

  function itemSearch(id) {
    if (!selected.includes(id)) selected.push(id);
  }

  function onBound(e) {
    this.value = selected;
  }

  function onfiltering(e) {
    var query = new ej.data.Query();
    if (e.text) query = query.where('Type','startswith',e.text,true);
    e.updateData(@Html.Raw(JsonConvert.SerializeObject(ViewBag.data)), query);
  }

  // Syncfusion ripple effect on inputs
  ej.base.enableRipple(true);
  document.querySelectorAll('.e-input-group .e-input').forEach(input => {
    input.addEventListener('focus', ()=> input.parentNode.classList.add('e-input-focus'));
    input.addEventListener('blur', ()=> input.parentNode.classList.remove('e-input-focus'));
  });
</script>
  • onBegin / onBound manage pre‑selection for multi‑select
  • onfiltering enables live search in the dropdown
  • Final block applies ripple focus to Syncfusion inputs

6. Error Handling & Validation

  • Data Annotations on the server side drive client errors via:
    • asp-validation-summary="ModelOnly"
    • span tags with asp-validation-for
  • Required attribute in the Type field ensures non‑emptiness
  • No custom try/catch in view; server‑side action should catch and re‑render with ModelState errors.

7. UML Class Diagram

classDiagram
    class DocumentTypeView {
      +int Id
      +string Type
      +string Description
      +int Category
      +bool IsAvailable
      +bool IsDeleted
      +ImagingType ImagingType
      +bool IsLegal
      +bool IsSafety
      +bool IsIT
      +bool IsAccounting
      +bool IsBidding
    }

This diagram shows the key properties that the view binds to.


8. Usage Examples

  1. Navigate to Edit
    • URL: /AccountingImaging/EditType/{id}
    • Controller: AccountingImagingController.EditType(int id)
  2. Populate ViewBag
    ViewBag.type    = GetDocumentCategories();
    ViewBag.indexes = GetIndexTypes();
    ViewBag.data    = GetIndexTypes(); // for filtering source
    return View(model);
    
  3. Handle POST
    [HttpPost]
    public IActionResult EditDocType(DocumentTypeView vm) {
        if (!ModelState.IsValid) {
            // repopulate dropdown sources & return view
        }
        _docService.Update(vm);
        return RedirectToAction("DocumentTypes", new { imagingType = vm.ImagingType });
    }
    

9. Conclusion

This EditType.cshtml Razor view combines ASP.NET Core Tag Helpers, Syncfusion EJ2 controls, and custom JavaScript to deliver a rich “Edit Document Type” experience. It:

  • Ensures consistency across multiple imaging areas (Legal, Safety, IT, Accounting, Bidding)
  • Leverages modern UI controls for better usability
  • Maintains strong server‑side validation
  • Provides extensibility points (e.g., filtering, multi‑select events)

With this documentation, developers can confidently maintain or extend the view—for example, adding new metadata fields or custom validation rules. 🚀