📄 Documentation: _myModalAttribute.cshtml
Location:
IrbyImaging/Views/AccountingImaging/_myModalAttribute.cshtml
Type: ASP.NET Core MVC Razor Partial View
Purpose: Renders a Bootstrap modal displaying Document Types for a given Document Category.
📑 Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Models & Data Models
- Layout & Structure
- Helper Methods & Utilities
- Error Handling & Return Types
- API Endpoints Overview
- Third‑Party Integrations
- UML Class Diagram
- Sample Code Blocks
- Usage Examples
- Conclusion
🔍 Overview & Purpose
This Razor partial view renders a Bootstrap modal that displays:
- The Index Name (i.e., category name).
- A list of Document Types associated with that category.
It is intended to be invoked from within any Accounting‑related view (e.g., transaction lists), providing users with a quick, in‑page detail view without full page reloads.
🛠️ Key Functional Areas
| Area | Description |
|---|---|
| Modal Title | Static heading: “Document Types”. |
| Index Name Display | Shows the Name property in blue via @Html.DisplayFor. |
| Document Types Listing | Iterates Model.TypeList to show each type; fallback when empty. |
| Modal Footer Buttons | A Close button to dismiss the modal; placeholder for future actions (e.g., Print). |
📦 Dependencies & Technologies
- ASP.NET Core MVC – Razor syntax,
@model,@Html.DisplayFor,@Html.Raw. - Bootstrap 5 – Modal structure, classes:
modal-content,modal-header,btn-close,btn, etc. - JavaScript – Relies on Bootstrap’s JS for modal show/hide.
- CSS – Inline style for
.line-breaks(pre-line whitespace).
🗂️ View Models & Data Models
DocumentCategoryView (UI.Model)
This view expects a strongly‑typed model:
| Property | Type | Description |
|---|---|---|
Name |
string |
The index or category name. |
TypeList |
IEnumerable<string> |
List of document type names. |
Preview |
bool |
Flag indicating preview capabilities (unused). |
Note: The
Previewflag is commented out in the footer for potential Print functionality.
🏗️ Layout & Structure
@model IrbyImaging.UI.Models.DocumentCategoryView
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Document Types</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<style>
.line-breaks { white-space: pre-line; }
</style>
<div class="modal-body">
<p>Index Name: <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>No Document Types are Assigned to this Index</span>
}
</div>
</div>
<div class="modal-footer">
<!-- Optional Print Button (commented out) -->
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
@modelDirective: Binds the partial toDocumentCategoryView.- Modal Header: Title + close button.
- Modal Body:
- Displays Index Name.
- Iterates and renders each Document Type.
- Fallback message when list is empty.
- Modal Footer: Single Close button; potential for Print.
🔧 Helper Methods & Utilities
- @Html.DisplayFor(...) – Renders the
Nameproperty using standard display templates. - @Html.Raw("") – Emits a raw
<br>tag between document types. white-space: pre-wrap;– Ensures long type names line‑wrap appropriately.- Conditional Logic:
@if (Model.TypeList.Any())to guard against empty collections.
🛡️ Error Handling & Return Types
- Empty List: Graceful message:
No Document Types are Assigned to this Index
- Model Null Check: Ensure calling code never passes a
nullmodel. Best practice:if (model == null) throw new ArgumentNullException(nameof(model)); - HTML Encoding:
@Html.DisplayForauto-encodes; raw HTML limited to<br />.
🌐 API Endpoints Overview
This partial view itself does not define API endpoints. It is typically invoked by:
- Controller Action (e.g.,
AccountingImagingController.GetCategoryModal(int id)). - AJAX Call – Returns
PartialView("_myModalAttribute", viewModel). - JavaScript – Injects returned HTML into the DOM and calls
bootstrap.Modal.show().
🔗 Third‑Party Integrations
- Bootstrap 5 (CSS & JS) – for modal styling and behavior.
- jQuery (optional) – if AJAX is used to load this partial dynamically.
📈 UML Class Diagram
classDiagram
class DocumentCategoryView {
+ string Name
+ List~string~ TypeList
+ bool Preview
}
💡 Sample Code Blocks
Controller Action Example (C#)
public IActionResult GetDocumentTypesModal(int categoryId)
{
var category = _documentService.GetCategoryById(categoryId);
var viewModel = new DocumentCategoryView
{
Name = category.Name,
TypeList = category.Types.ToList(),
Preview = false
};
return PartialView("_myModalAttribute", viewModel);
}
AJAX Call (JavaScript / jQuery)
function showDocumentTypes(categoryId) {
$.get('/AccountingImaging/GetDocumentTypesModal', { id: categoryId })
.done(function(html) {
$('#modalContainer').html(html);
var modal = new bootstrap.Modal(document.querySelector('.modal-content'));
modal.show();
})
.fail(function() {
alert('Failed to load document types.');
});
}
🚀 Usage Examples
- Include a placeholder in your main view:
<div id="modalContainer"></div> - Trigger via button:
<button class="btn btn-info" onclick="showDocumentTypes(@item.CategoryId)"> View Doc Types </button> - Result:
- AJAX loads the partial view →
- Modal appears with Index Name + List of Types →
- User clicks Close to dismiss.
🏁 Conclusion
The _myModalAttribute.cshtml partial provides a lightweight, reusable modal component to display Document Types for a given Document Category. Leveraging ASP.NET Core MVC and Bootstrap 5, it integrates seamlessly into the AccountingImaging area, delivering a responsive, user‑friendly detail view without full page reloads.
Feel free to extend the footer for Print, Edit, or other actions by un-commenting the Model.Preview block and integrating your custom logic. Enjoy building a dynamic, modular UI! 🎉