📄 _myModalCategory.cshtml Documentation
Location:
IrbyImaging/Views/AccountingImaging/_myModalCategory.cshtml
Purpose: Partial Razor view that renders a Bootstrap 5 modal displaying a document category and its associated document types.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Model & Data Models
- HTML Structure & Styling
4.1 Modal Header
4.2 Modal Body
4.3 Modal Footer - Key Functional Areas
- Helper Methods & Utilities
- Error Handling & Edge Cases
- Usage Examples
- UML Diagram
- Conclusion
1. Overview & Purpose 🎯
The _myModalCategory.cshtml file is a reusable partial view designed to present a modal dialog that:
- Shows the name of a document category.
- Lists all types belonging to that category.
- Adapts to empty lists by displaying a friendly message.
It is most often invoked from within the Accounting Imaging pages whenever a user requests details for a particular document category.
2. Dependencies & Technologies ⚙️
| Technology | Usage |
|---|---|
| ASP.NET Core MVC | Razor view engine & model binding |
| Bootstrap 5 | Modal components, responsive classes, buttons |
| C# / .NET Standard | ViewModel definition |
| Razor HTML Helpers | @Html.DisplayFor, @Html.Raw |
3. View Model & Data Models 📦
DocumentCategoryView
This partial expects a model of type IrbyImaging.UI.Models.DocumentCategoryView, defined roughly as:
namespace IrbyImaging.UI.Models
{
public class DocumentCategoryView
{
public string Name { get; set; }
public IEnumerable<string> TypeList { get; set; }
public bool Preview { get; set; } // Optional flag for future “Print” feature
}
}
| Property | Type | Description |
|---|---|---|
| Name | string |
The document category’s display name. |
| TypeList | IEnumerable<string> |
A collection of document type names. |
| Preview | bool |
(Optional) Determines if “Print” button shows. |
4. HTML Structure & Styling 📐
@model IrbyImaging.UI.Models.DocumentCategoryView
<div class="modal-content">
<div class="modal-header"> ... </div>
<style> .line-breaks { white-space: pre-line; } </style>
<div class="modal-body"> ... </div>
<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>
- Title: Static text “Document Types”.
- Close Button: Uses Bootstrap’s
.btn-close.
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.Count() > 0)
{
foreach (var val in Model.TypeList)
{
<span style="white-space: pre-wrap">@val</span>
@Html.Raw("<br />")
}
}
else
{
<span>No Document Types are Assigned to this Document Type</span>
}
</div>
</div>
- Displays category name in a primary-colored span.
- Iterates through
TypeList:- Non‑empty: Renders each type name with line breaks.
- Empty: Shows a fallback message.
- Wrapped in
.table-responsivefor better mobile support.
4.3 Modal Footer
<div class="modal-footer">
@* Optional “Print Document” button based on `Model.Preview` *@
@*
@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.
- Print button is commented-out as a placeholder for a “preview” feature.
5. Key Functional Areas 🔑
- Model Binding:
@model DocumentCategoryView - Conditional Rendering:
@if … elsefor empty vs. non-empty lists. - HTML Helpers:
@Html.DisplayFor(m => m.Name)to render the category name.@Html.Raw("<br />")for manual line breaks.
- Bootstrap 5 Integration:
.modal-content,.btn-close,.btn-secondary, etc.
6. Helper Methods & Utilities 🔧
- Built‑in Razor HTML helpers only.
- Inline CSS:
.line-breaks { white-space: pre-line; }Note: This class is declared but not used in the current markup.
7. Error Handling & Edge Cases ⚠️
- Null Model
- Ensure controller action passes a non-null
DocumentCategoryView.
- Ensure controller action passes a non-null
- Empty
TypeList- Gracefully handled by the
elsebranch.
- Gracefully handled by the
- Long Texts
- Wrapped via
white-space: pre-wrapto preserve readability.
- Wrapped via
8. Usage Examples 📋
1. Rendering the Modal Partial
@model IrbyImaging.UI.Models.DocumentCategoryView
<!-- Trigger button -->
<button type="button"
class="btn btn-primary"
data-bs-toggle="modal"
data-bs-target="#categoryModal">
Show Document Types
</button>
<!-- Modal container -->
<div id="categoryModal" class="modal fade" tabindex="-1">
@Html.Partial("_myModalCategory", Model)
</div>
2. Showing the Modal via JavaScript
// Bootstrap 5 Modal API
const modalEl = document.getElementById('categoryModal');
const bsModal = new bootstrap.Modal(modalEl);
bsModal.show();
3. Sample Server‑Side Setup
public IActionResult Details(int categoryId)
{
var vm = new DocumentCategoryView
{
Name = "Invoices",
TypeList = _service.GetTypesForCategory(categoryId),
Preview = false
};
return View(vm);
}
9. UML Diagram 📈
classDiagram
class DocumentCategoryView {
+ string Name
+ IEnumerable<string> TypeList
+ bool Preview
}
class _myModalCategory {
<<RazorView>>
+ @model DocumentCategoryView
}
10. Conclusion 🏁
The _myModalCategory.cshtml partial is a simple, clean, and extensible Razor view that provides:
- A consistent UI pattern for displaying document kinds and their types.
- Responsive layout using Bootstrap’s grid & utility classes.
- A hook (
Model.Preview) for future enhancements (e.g., printing).
By following this template, developers can quickly plug in new document categories and types without rewriting the modal logic, ensuring consistency across the Accounting Imaging module.
Enjoy seamless, maintainable UI components! 🎉