📋 _myModalCategory.cshtml Documentation


Table of Contents

  1. Overview & Purpose 🎯
  2. Dependencies & Technologies ⚙️
  3. View Model & Data Models 📦
  4. Key Functional Areas 🗂️
  5. Helper Methods & Utilities 🛠️
  6. Error Handling & Conditions 🚨
  7. Usage Examples 💡
  8. UML Diagram 📊
  9. Conclusion 🎉

1. Overview & Purpose 🎯

_myModalCategory.cshtml is a Razor View Partial in the HRImaging area of the IrbyImaging application. Its primary function is to render a Bootstrap 5 modal that displays:

  • The name of a document category.
  • A list of document types associated with that category.
  • A Close button (and an optional Print button if needed).

This partial is intended to be reused anywhere in the UI where the user needs to inspect which document types belong to a given category.


2. Dependencies & Technologies ⚙️

Technology Purpose
ASP.NET MVC / Razor Server‑side templating
Bootstrap 5 CSS/JS Modal styling & behavior
jQuery (optional) Triggering the modal (if not using pure JS)
IrbyImaging.UI.Models DocumentCategoryView model for strongly‑typed data

3. View Model & Data Models 📦

This partial is strongly‑typed to the IrbyImaging.UI.Models.DocumentCategoryView class.

Property Type Description
Name string The name of the document category
TypeList IEnumerable<string> The list of document types under this category
Preview bool (optional) Indicates if a Print button should appear
namespace IrbyImaging.UI.Models
{
    public class DocumentCategoryView
    {
        public string Name { get; set; }
        public IEnumerable<string> TypeList { get; set; } = new List<string>();
        public bool Preview { get; set; }
    }
}

4. Key Functional Areas 🗂️

@model IrbyImaging.UI.Models.DocumentCategoryView

<div class="modal-content">
  <!-- HEADER -->
  <div class="modal-header"> … </div>

  <!-- INLINE STYLES (Scoped) -->
  <style> .line-breaks { white-space: pre-line; } </style>

  <!-- BODY -->
  <div class="modal-body"> … </div>

  <!-- FOOTER -->
  <div class="modal-footer"> … </div>
</div>

4.1 Modal Header 🏷️

<div class="modal-header">
  <h5 class="modal-title" id="transaction-detailModalLabel">
    Document Types
  </h5>
  <button type="button"
          class="btn-close"
          data-bs-dismiss="modal"
          aria-label="Close">
  </button>
</div>
  • .modal-title: Fixed title “Document Types”.
  • .btn-close: Bootstrap’s default close button.

4.2 Modal Body 📄

<div class="modal-body">
  <p class="mb-2">
    Document Category:
    <span class="text-primary">
      @Html.DisplayFor(m => m.Name)
    </span>
  </p>

  <div class="table-responsive">
    @if (Model.TypeList.Any()) {
      foreach (var val in Model.TypeList) {
        <span style="white-space: pre-wrap">
          @val
        </span>
        @Html.Raw("<br />")
      }
    }
    else {
      <span style="white-space: pre-wrap">
        No Document Types are Assigned to this Document Type
      </span>
    }
  </div>
</div>
  • Category Name: Rendered with @Html.DisplayFor.
  • Type List:
    • Loops through Model.TypeList.
    • Uses inline style white-space: pre-wrap for preserving line breaks.
    • Fallback message if the list is empty.
<div class="modal-footer">
  @* Optional Print Button *@
  @* 
  @if (Model.Preview) {
    <button type="button"
            class="btn btn-secondary"
            data-bs-dismiss="modal">
      Print Document
    </button>
  }
  *@

  <button type="button"
          class="btn btn-secondary"
          data-bs-dismiss="modal">
    Close
  </button>
</div>
  • Close Button: Always visible to dismiss the modal.
  • Print Button: Commented out — can be enabled by checking Model.Preview.

5. Helper Methods & Utilities 🛠️

Helper Usage & Remarks
@Html.DisplayFor(...) Safely renders model property as HTML‑encoded text
@Html.Raw(...) Renders raw HTML (used for <br /> line breaks)
Inline <style> Defines .line-breaks if additional formatting needed

6. Error Handling & Conditions 🚨

  • Empty List Check:
    @if (Model.TypeList.Any()) { … } else { … }
    
    Ensures user sees a fallback message when there are no document types.
  • Strongly‑Typed Model:
    If Model is null, Razor will throw. Always ensure a valid DocumentCategoryView is passed in.

7. Usage Examples 💡

7.1 Rendering the Partial in a Parent View

@using IrbyImaging.UI.Models

<button class="btn btn-primary"
        data-bs-toggle="modal"
        data-bs-target="#categoryModal">
  View Category Types
</button>

<div class="modal fade" id="categoryModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    @Html.Partial(
      "_myModalCategory",
      new DocumentCategoryView {
        Name     = "Policies",
        TypeList = new List<string> { "Safety", "HR Guidelines" },
        Preview  = true
      }
    )
  </div>
</div>

7.2 Triggering via JavaScript

// Assuming you load category data via AJAX:
fetch('/api/documents/categories/5/types')
  .then(res => res.json())
  .then(data => {
    // Render partial server-side or client-side injection
    $('#categoryModal .modal-dialog').html(data.html);
    $('#categoryModal').modal('show');
  });

8. UML Diagram 📊

classDiagram
  class DocumentCategoryView {
    +string Name
    +IEnumerable~string~ TypeList
    +bool Preview
  }

9. Conclusion 🎉

The _myModalCategory.cshtml partial is a clean, reusable component for showing document‐category relationships in a modal. Leveraging Bootstrap 5 and Razor, it adapts to dynamic data with:

  • Clear separation of header, body, and footer.
  • Graceful handling of empty data sets.
  • Easy extension (e.g., enabling print functionality).

Use this partial wherever you need a standardized UI for document category details!