📝 Documentation for _myModalIndexes.cshtml


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Models
  4. Key Functional Areas
  5. Helper Methods & Utilities
  6. Third-Party Integrations
  7. Sample Code Blocks
  8. Usage Examples
  9. UML Class Diagram
  10. Conclusion

1. Overview & Purpose

This Razor partial view renders a dynamic indexing form for the DocumentImaging model. It loops through an IndexList—each entry describing a metadata field—and emits the appropriate input control based on:

  • Attribute type (Date, Currency, Number, Boolean, Text)
  • Multi‑value flags
  • Linked data sources (Employees, Jobs, Customers, States)

🔍 Use Case: Display and capture metadata fields in a modal dialog when scanning or filing documents.


2. Dependencies & Technologies

Category Details
Language C#, Razor (.cshtml)
Framework ASP.NET Core MVC
Client Libraries jQuery, Select2, Syncfusion EJ2
JSON Serializer Newtonsoft.Json
Tag Helpers asp-for, asp-items

3. View Model & Data Models

// DocumentImaging.cs
public class DocumentImaging {
    public List<IndexItem> IndexList { get; set; }
    public IEnumerable<SelectListItem> EmployeeData { get; set; }
    public IEnumerable<SelectListItem> JobData { get; set; }
    public IEnumerable<SelectListItem> CustomerData { get; set; }
    public IEnumerable<SelectListItem> CustomerData1 { get; set; }
    public IEnumerable<SelectListItem> StateData { get; set; }
}

// IndexItem.cs
public class IndexItem {
    public int Id { get; set; }
    public string AttributeName { get; set; }
    public string IndexValue { get; set; }
    public bool IsMultiValue { get; set; }
    public AttributeType AttributeType { get; set; }
    public bool IsRequired { get; set; }
    public bool LinkEmployeeData { get; set; }
    public bool LinkJobData { get; set; }
    public bool LinkCustomerData { get; set; }
    public IEnumerable<SelectListItem> MultiValueTypes { get; set; }
}

public enum AttributeType {
    Text,
    Number,
    Currency,
    Date,
    Boolean
}

4. Key Functional Areas

4.1 Hidden Inputs

For every IndexItem, the view emits hidden fields to maintain state:

<input type="hidden" asp-for="@Model.IndexList[i].Id" />
<input type="hidden" asp-for="@Model.IndexList[i].AttributeName" />
<!-- ...and so on for IndexValue, IsMultiValue, AttributeType, etc. -->

⚙️ Why?
These ensure that on form postback, the server knows which attribute was rendered and retains its metadata.


4.2 Dynamic Field Rendering

Depending on IndexItem.IsMultiValue or AttributeType, a matching input is shown:

Condition Control
IsMultiValue == true <select> with MultiValueTypes
AttributeType == Date <input type="date">
AttributeType == Currency <input type="number" step="0.01" …>
AttributeType == Number <input type="number">
AttributeType == Boolean <input type="checkbox">
<div class="row mb-4">
  <label class="col-form-label col-lg-3">@Model.IndexList[i].AttributeName</label>
  <div class="col-lg-9">
    <input name="IndexValue" type="date" autocomplete="off" />
  </div>
</div>

4.3 Linked Data Dropdowns

When LinkEmployeeData, LinkJobData or LinkCustomerData flags are set, specialized <select> fields populate from:

  • Model.EmployeeData
  • Model.JobData
  • Model.CustomerData / Model.CustomerData1
  • Model.StateData

💡 Dynamic IDs:
IDs like id="employee", id="job", id="customer" tie in with the Select2 and Syncfusion filters.


4.4 Default Textarea Fallback

If no special type or link-flag applies, a <textarea> is rendered:

<textarea asp-for="@Model.IndexList[i].IndexValue"
          id="@Model.IndexList[i].AttributeName"
          name="IndexValue"
          class="form-control"
          placeholder="Enter @Model.IndexList[i].AttributeName …">
</textarea>
<input type="hidden" name="IndexValue" value=" " />

5. Helper Methods & Utilities

onfiltering (Syncfusion EJ2)

function onfiltering(e) {
  var query = new ej.data.Query();
  query = (e.text !== '')
    ? query.where('Name', 'startswith', e.text, true)
    : query;
  e.updateData(@Html.Raw(JsonConvert.SerializeObject(ViewBag.data)), query);
}
  • Purpose: Client-side filtering callback for Syncfusion MultiSelect.
  • Input: e.text (user input).
  • Output: Updates dropdown data dynamically.

Select2 Initialization

$(document).ready(function() {
  $('.js-example-basic-single').select2();
});
  • Activates Select2 on any <select> with js-example-basic-single class.

6. Third-Party Integrations

Library Usage
jQuery DOM manipulation, ready handler
Select2 Enhanced <select> UX with search/filtering
Syncfusion EJ2 (Commented-out) MultiSelect & filtering widgets
Newtonsoft.Json Serializing server data into JS (ViewBag.data)

7. Sample Code Blocks

Rendering a Currency Field

@if (Model.IndexList[i].AttributeType == AttributeType.Currency) {
  <div class="row mb-4">
    <label class="col-form-label col-lg-3">@Model.IndexList[i].AttributeName</label>
    <div class="col-lg-9">
      $ <input name="IndexValue"
               id="@Model.IndexList[i].AttributeName"
               value="0.00"
               type="number"
               min="0.00"
               step="0.01" />
    </div>
  </div>
}

Multi-Value Dropdown

@if (Model.IndexList[i].IsMultiValue) {
  <div class="row mb-4">
    <label class="col-form-label col-lg-3">@Model.IndexList[i].AttributeName</label>
    <div class="col-lg-9">
      <select name="IndexValue"
              id="@Model.IndexList[i].AttributeName"
              class="form-control col-sm-6"
              asp-items="@Model.IndexList[i].MultiValueTypes">
        <option value="None Selected" selected disabled hidden>
          Select @Model.IndexList[i].AttributeName Value
        </option>
      </select>
    </div>
  </div>
}

8. Usage Examples

  1. Controller populates DocumentImaging:
    public IActionResult Index() {
      var model = new DocumentImaging {
        IndexList = GetIndexDefinitions(),
        EmployeeData = GetEmployees(),
        JobData = GetJobs(),
        CustomerData = GetCustomers(),
        CustomerData1 = GetCustomerNames(),
        StateData = GetStates()
      };
      ViewBag.data = model.EmployeeData; // for Syncfusion filtering
      return PartialView("_myModalIndexes", model);
    }
    
  2. View loads modal via AJAX:
    $('#myModal .modal-body')
      .load('/LegalImaging/Index', function() {
        $('#myModal').modal('show');
      });
    

9. UML Class Diagram

classDiagram
    class DocumentImaging {
      +List~IndexItem~ IndexList
      +IEnumerable~SelectListItem~ EmployeeData
      +IEnumerable~SelectListItem~ JobData
      +IEnumerable~SelectListItem~ CustomerData
      +IEnumerable~SelectListItem~ CustomerData1
      +IEnumerable~SelectListItem~ StateData
    }

    class IndexItem {
      +int Id
      +string AttributeName
      +string IndexValue
      +bool IsMultiValue
      +AttributeType AttributeType
      +bool IsRequired
      +bool LinkEmployeeData
      +bool LinkJobData
      +bool LinkCustomerData
      +IEnumerable~SelectListItem~ MultiValueTypes
    }

    DocumentImaging "1" *-- "*" IndexItem

10. Conclusion

This partial view drives the metadata indexing feature within the Legal Imaging module.
🔑 Key Takeaways:

  • Dynamic Rendering: Field types adapt to attribute definitions.
  • Hidden State: Data integrity via hidden inputs.
  • Rich UX: Integration with Select2 and Syncfusion for searchable dropdowns.
  • Extensibility: Easily add new attribute types or linked data sources.

By following this pattern, you can maintain a flexible, metadata‑driven UI for diverse document workflows.
Happy coding! 🎉


End of _myModalIndexes.cshtml Documentation