📁 _myModalCategory.cshtml Documentation
Location:
IrbyImaging/Views/LegalImaging/_myModalCategory.cshtml
📑 Table of Contents
- Overview & Purpose
- File Structure & Location
- Dependencies & Technologies
- Model Binding
- Razor + HTML Structure
- Custom CSS Styling
- Conditional Rendering & Logic
- Usage Examples
- UML Diagram
- Integration & Triggering
- 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-wrapis used per‑span to preserve formatting.
7. Conditional Rendering & Logic
-
Has Types?
@if (Model.TypeList.Any())- Loops through each string in
TypeListand renders with<span>+<br>
-
No Types
- Renders fallback message:
“No Document Types are Assigned to this Document Type”
- Renders fallback message:
-
Preview Button (Optional)
- Commented out block for a “Print Document” button, toggled by
Model.Preview.
- Commented out block for a “Print Document” button, toggled by
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
- Load Styles & Scripts
- Ensure Bootstrap 5 CSS & JS are included in your
_Layout.cshtml.
- Ensure Bootstrap 5 CSS & JS are included in your
- Partial Injection
- Either server‑side (via
@Html.Partial) or client‑side (AJAX)
- Either server‑side (via
- Modal Show/Hide
- Use
bootstrap.ModalJS API ordata-bs-toggle="modal"attribs
- Use
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! 🚀