📁 _myModalCategory.cshtml Documentation

Location: IrbyImaging/Views/LegalImaging/_myModalCategory.cshtml


📑 Table of Contents

  1. Overview & Purpose
  2. File Structure & Location
  3. Dependencies & Technologies
  4. Model Binding
  5. Razor + HTML Structure
  6. Custom CSS Styling
  7. Conditional Rendering & Logic
  8. Usage Examples
  9. UML Diagram
  10. Integration & Triggering
  11. Conclusion

1. Overview & Purpose

This Razor partial view renders a Bootstrap 5 modal dialog that displays:

  • Document Category name
  • A list of associated Document Types

It is used in the Legal Imaging section of the IrbyImaging application to give end‑users a quick, friendly overview of which document types belong to a given category.

Emoji key:

  • 🗂️ Category info
  • 📜 Document type list
  • ❗ Graceful fallback if no types

2. File Structure & Location

IrbyImaging/
└─ Views/
   └─ LegalImaging/
      └─ _myModalCategory.cshtml   ← Partial view for Document Category modal
  • Naming Convention: Leading underscore (_) indicates a partial view.
  • Purpose: Easily inject this modal markup into any parent view or layout.

3. Dependencies & Technologies

Technology Purpose
ASP.NET MVC Razor Server‑side view engine for generating HTML.
Bootstrap 5 Modal structure (.modal-content, .btn-close, etc.).
HTML / CSS General markup & inline styles.
C# Model Binding @model IrbyImaging.UI.Models.DocumentCategoryView

Note: No direct JavaScript references are in this file; it relies on your layout importing Bootstrap’s JS bundle.


4. Model Binding

At top of the file:

@model IrbyImaging.UI.Models.DocumentCategoryView

Model properties used:

Property Type Description
Name string Category name shown in modal header/body.
TypeList IEnumerable<string> List of document types under this category.
Preview? bool (optional) (Commented) Flag to show “Print” button.

5. Razor + HTML Structure

<div class="modal-content">
  <!-- 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>

  <!-- Custom Styles -->
  <style>
    .line-breaks {
      white-space: pre-line;
    }
  </style>

  <!-- 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">
      @* Loop through each type *@
      @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>

  <!-- Footer -->
  <div class="modal-footer">
    @*<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>
</div>
  • Header: Title + Close (.btn-close)
  • Body:
    • Category name
    • Responsive container for type list
  • Footer:
    • (Commented) “Print Document” button
    • Always‑visible “Close” button

6. Custom CSS Styling

.line-breaks {
  white-space: pre-line;
}
  • Ensures that any newline characters in text are rendered as line breaks.
  • In this file, inline style white-space: pre-wrap is used per‑span to preserve formatting.

7. Conditional Rendering & Logic

  1. Has Types?

    • @if (Model.TypeList.Any())
    • Loops through each string in TypeList and renders with <span> + <br>
  2. No Types

    • Renders fallback message:

      “No Document Types are Assigned to this Document Type”

  3. Preview Button (Optional)

    • Commented out block for a “Print Document” button, toggled by Model.Preview.

8. Usage Examples

8.1 Rendering from a Controller

public IActionResult ShowCategoryModal(int categoryId)
{
    var model = _documentService
                  .GetCategoryViewById(categoryId); // Returns DocumentCategoryView

    return PartialView("_myModalCategory", model);
}

8.2 Triggering the Modal in a Parent View

<!-- Placeholder to load the partial -->
<div id="categoryModalContainer"></div>

<!-- Button to launch modal -->
<button class="btn btn-primary" onclick="loadCategoryModal(5)">
  View Document Types
</button>

<script>
function loadCategoryModal(categoryId) {
  fetch(`/LegalImaging/ShowCategoryModal?categoryId=${categoryId}`)
    .then(res => res.text())
    .then(html => {
      document.getElementById('categoryModalContainer').innerHTML = html;
      // Use Bootstrap 5 Modal JS API
      var myModal = new bootstrap.Modal(
        document.querySelector('#categoryModalContainer .modal-content')
      );
      myModal.show();
    });
}
</script>

9. UML Diagram

+----------------------------------------+
|        DocumentCategoryView            |
+----------------------------------------+
| - Name: string                         |
| - TypeList: IEnumerable<string>        |
| - Preview: bool (optional)             |
+----------------------------------------+
| + <ctor>()                             |
+----------------------------------------+

10. Integration & Triggering

  1. Load Styles & Scripts
    • Ensure Bootstrap 5 CSS & JS are included in your _Layout.cshtml.
  2. Partial Injection
    • Either server‑side (via @Html.Partial) or client‑side (AJAX)
  3. Modal Show/Hide
    • Use bootstrap.Modal JS API or data-bs-toggle="modal" attribs

11. Conclusion

This partial view encapsulates the Document Category ➡️ Document Types modal in a concise, reusable component. By simply passing in a DocumentCategoryView model, you gain:

  • 🎯 Focus: Clearly display category & types
  • 🔄 Reusability: Drop into any view/layout
  • 💅 Styling: Seamless with Bootstrap 5

Feel free to extend with print functionality, richer formatting, or animations! 🚀