📝 EditAttribute.cshtml Documentation


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. ViewModel & Data Model
  4. Layout & Page Titles
  5. Form Structure & Fields
    • 5.1. Hidden Fields
    • 5.2. Read‑only Inputs
    • 5.3. Index Values TextArea
    • 5.4. Document Types MultiSelect
    • 5.5. Action Buttons
  6. Key Scripts & Client‑Side Behavior
    • 6.1. MultiSelect: onBegin, onBound
    • 6.2. Filtering: onfiltering
    • 6.3. Ripple Effect Initialization
  7. Controller & Endpoint Overview
  8. UML Class Diagram
  9. Usage Example
  10. Conclusion

1. Overview & Purpose

This Razor view (EditAttribute.cshtml) is part of the IrbyImaging web application under the Views/LegalImaging folder. It provides a user interface for updating an existing document-attribute type.

🔍 **Key Goals:
**

  • Display current attribute details (name, required/multivalue flags, linked data flags) in read‑only form.
  • Allow the user to update the attribute’s index values and assign it to one or more document types.
  • Submit the changes to the EditAttributeType action for server‑side processing.

2. Dependencies & Technologies

Library / Technology Purpose
ASP.NET Core Razor Server‑side view engine
Syncfusion.EJ2 JavaScript Rich UI components (MultiSelect)
Newtonsoft.Json Serializing ViewBag.data for client‑side filtering
HTML5, CSS, Bootstrap 4 Layout and responsive grid

3. ViewModel & Data Model

Model bound to this view:

public class DocumentAttributeView {
  public int Id { get; set; }
  public string AttributeName { get; set; }
  public bool IsMultiValue { get; set; }
  public bool IsRequired { get; set; }
  public bool LinkEmployeeData { get; set; }
  public bool LinkJobData { get; set; }
  public string Values { get; set; }
  public ImagingType ImagingType { get; set; }
  public bool IsLegal { get; set; }
  public bool IsSafety { get; set; }
  public bool IsIT { get; set; }
  // (Potentially) List<int> SelectedDocumentTypeIds { get; set; }
}

Supporting Enumeration:

public enum ImagingType {
  Legal,
  Safety,
  IT
}

4. Layout & Page Titles

@{
    ViewBag.Title     = "Update Attribute Type";
    ViewBag.pTitle    = "Update Attribute Types";
    ViewBag.pageTitle = "Update Attribute Types";
    Layout           = "~/Views/Shared/_LegalLayout.cshtml";
}
  • Layout: _LegalLayout.cshtml maintains consistent header/footer for Legal Imaging area.
  • ViewBag sets the browser title and on‑page headings.

5. Form Structure & Fields

<form asp-action="EditAttributeType" method="post" enctype="multipart/form-data">
  @* Hidden & Read‑only fields *@
  @Html.HiddenFor(m => m.ImagingType)
  @Html.HiddenFor(m => m.IsLegal)
  ...
  @Html.HiddenFor(m => m.IsIT)

  <!-- Read‑only Text Inputs -->
  <input type="text" id="attributeName"    value="@Model.AttributeName" readonly required />
  <input type="text" id="multivalue"       value="@Model.IsMultiValue" readonly required />
  <input type="text" id="isRequired"       value="@Model.IsRequired" readonly required />
  <input type="text" id="employeeData"     value="@Model.LinkEmployeeData" readonly required />
  <input type="text" id="jobData"          value="@Model.LinkJobData" readonly required />

  <!-- Editable TextArea for Index Values -->
  <textarea id="indexvalues" name="indexvalues">@Model.Values</textarea>

  <!-- Syncfusion MultiSelect for Document Types -->
  <ejs-multiselect id="doctype"
                   dataSource="@ViewBag.data"
                   placeholder="Select Document Types"
                   mode="CheckBox" allowFiltering="true"
                   filtering="onfiltering"
                   actionBegin="onBegin"
                   dataBound="onBound"
                   popupHeight="200px">
    <e-multiselect-fields text="Type" value="Id" groupBy="Category"></e-multiselect-fields>
  </ejs-multiselect>

  <!-- Buttons -->
  <a asp-action="DocumentAttributes" asp-route-category="@category"
     asp-controller="LegalImaging" class="btn btn-danger">Back</a>
  <input type="submit" value="Update" class="btn btn-success" />
</form>

5.1 Hidden Fields

Field Bound Property Purpose
ImagingType Model.ImagingType Determines current imaging category
IsLegal Model.IsLegal Legal flag for server‑side logic
IsSafety Model.IsSafety Safety flag
IsIT Model.IsIT IT flag
modelId Model.Id Primary key for the record to update

5.2 Read‑only Inputs

Why read‑only?
The attributes such as name or “Is Required” are fixed once created; only the values and document‑type mappings can be changed here.

Input ID Bound Value Label
attributeName Model.AttributeName Index Name
multivalue Model.IsMultiValue Is Index Multi Value?
isRequired Model.IsRequired Is Index Value Required?
employeeData Model.LinkEmployeeData Link Employee Data?
jobData Model.LinkJobData Link Job Data?

5.3 Index Values TextArea

  • ID: indexvalues
  • Name: indexvalues
  • Purpose: Comma‑separated (or newline‑separated) list of valid index values.

5.4 Document Types MultiSelect

  • Syncfusion EJ2 <ejs-multiselect>
  • DataSource: ViewBag.data (List of { Id, Type, Category, IsSelected })
  • Features:
    • CheckBox mode
    • Grouped by Category
    • Filtering via onfiltering callback
    • Pre‑selection via onBegin / onBound events

5.5 Action Buttons

Button Text Type Action
Back Anchor Returns to DocumentAttributes list for current category
Update Submit Posts form to EditAttributeType action

6. Key Scripts & Client‑Side Behavior

6.1 MultiSelect: onBegin & onBound

var selected = [];

function onBegin(e) {
  this.fields = {
    text: 'Type',
    value: 'Id',
    itemCreated: function (args) {
      if (args.curData.IsSelected) {
        // collect pre‑selected IDs
        if (selected.indexOf(args.curData.Id) === -1) {
          selected.push(args.curData.Id);
        }
      }
    }
  };
}

function onBound(e) {
  // apply initial selected values
  this.value = selected;
}

Flow:

  1. onBegin sets up a custom itemCreated handler to detect IsSelected items in the data source.
  2. onBound assigns the collected IDs back to the component’s value.

6.2 Filtering: onfiltering

function onfiltering(e) {
  var query = new ej.data.Query();
  query = e.text !== '' 
    ? query.where('Type', 'startswith', e.text, true) 
    : query;
  e.updateData(@Html.Raw(JsonConvert.SerializeObject(ViewBag.data)), query);
}
  • Dynamically filters the dropdown by Type property when the user types in the search box.

6.3 Ripple Effect Initialization

ej.base.enableRipple(true);
var inputElement = document.querySelectorAll(
  '.e-input-group .e-input, .e-float-input.e-input-group input'
);
inputElement.forEach(function(el) {
  el.addEventListener('focus', function () {
    this.parentNode.classList.add('e-input-focus');
  });
  el.addEventListener('blur', function () {
    this.parentNode.classList.remove('e-input-focus');
  });
});
  • Enables Syncfusion “ripple” styling on focus/blur for a polished visual effect.

7. Controller & Endpoint Overview

[HttpGet]
public IActionResult EditAttributeType(int id, ImagingType imagingType) {
  // Fetch DocumentAttributeView by id
  return View(model);
}

[HttpPost]
public IActionResult EditAttributeType(DocumentAttributeView model, 
                                       string indexvalues, 
                                       List<int> doctype) {
  // 1. Validate input
  // 2. Update attribute entity
  // 3. Save selected DocumentType mappings
  // 4. Redirect back to DocumentAttributes listing
}
  • GET /LegalImaging/EditAttributeType — Display the form
  • POST /LegalImaging/EditAttributeType — Process the update

8. UML Class Diagram

@startuml
class DocumentAttributeView {
  +int Id
  +string AttributeName
  +bool IsMultiValue
  +bool IsRequired
  +bool LinkEmployeeData
  +bool LinkJobData
  +string Values
  +ImagingType ImagingType
  +bool IsLegal
  +bool IsSafety
  +bool IsIT
  +List<int> SelectedDocumentTypeIds
}

enum ImagingType {
  Legal
  Safety
  IT
}

DocumentAttributeView --> ImagingType
@enduml

Use a PlantUML renderer to visualize the above class relationships.


9. Usage Example

  1. Navigate to /LegalImaging/EditAttributeType?id=42&imagingType=Legal.
  2. Review read‑only fields (Index Name, flags).
  3. Adjust “Index Values” textarea (e.g. add “ValueA\nValueB”).
  4. Select one or more Document Types via the multi‑select dropdown.
  5. Click Update to apply changes.
  6. You are redirected back to the listing of attributes for the legal category.

10. Conclusion

🎯 EditAttribute.cshtml delivers a rich, interactive form for modifying document‑attribute metadata in the Legal Imaging module.

  • Syncfusion EJ2 enhances the UI with a checkbox‑style multiselect & filtering.
  • The form balances read‑only configuration with editable fields where appropriate.
  • Custom scripts ensure pre‑selection and polished ripple effects.

By following the patterns in this view, you can extend or replicate similar forms for other imaging categories (Safety, IT) within the IrbyImaging application.


Thank you for reading! 🚀