π Documentation: IrbyImaging/Views/CarrierType/Index.cshtml
π Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Models & Data Models
- UI Composition & Razor Elements
- Helper Methods & Utilities
- Error Handling & Return Types
- API Endpoints Overview
- Third-party Integrations
- Sample Code Blocks
- Usage Examples
- UML Sequence Diagram
- Conclusion
π 1. Overview & Purpose
File: IrbyImaging/Views/CarrierType/Index.cshtml
Responsibility:
This Razor View renders the Carrier Type List in a tabular format, complete with DataTables features (sorting, filtering, export). Itβs part of the ASP.NET Core MVC presentation layer for managing carrier types (e.g., shipping carriers).
Goal: Display existing carrier types, allow creation of new ones, and provide Update/Delete actions in an interactive table.
π 2. Key Functional Areas
| Section | Description |
|---|---|
| Page Setup & Metadata | Sets ViewData["Title"] and specifies the shared layout (_ATSLayout.cshtml). |
| Header & Badge | Displays the title βCarriersβ with a dynamic badge showing the total count. |
| Action Buttons | βAdd New Carrierβ button wired to the Create action. |
| DataTable Markup | Renders an HTML <table> with columns: Name, Available?, Update, Delete. |
| DataTable Initialization | Uses JavaScript to convert plain table into a DataTable with export buttons. |
π 3. Dependencies & Technologies
| Type | Library / Framework | Usage |
|---|---|---|
| ASP.NET Core MVC | Razor Pages / Views | Page templating, HTML helpers |
| jQuery | https://code.jquery.com/jquery-3.5.1.js |
DOM manipulation, plugin bootstrapping |
| DataTables CSS | Bootstrap 4, DataTables CDN | Table styling |
| DataTables JS | Buttons, JSZip, PDFMake | Export functionalities |
| CSS | dataTables.bootstrap4.min.css, buttons.dataTables.min.css |
Responsive & Buttons UI |
π 4. View Models & Data Models
// Model bound to this view:
@model IrbyImaging.DomainClasses.CarrierType
// Inside DomainClasses.CarrierType (simplified):
public class CarrierType
{
public IEnumerable<CarrierTypeDetail> CarriersTypeDetail { get; set; }
}
public class CarrierTypeDetail
{
public int Id { get; set; }
public string Carrier { get; set; }
public bool IsInactive { get; set; } // true = active, false = inactive
}
| Property | Type | Description |
|---|---|---|
CarriersTypeDetail |
IEnumerable<CarrierTypeDetail> |
Collection of carrier records to list. |
Carrier |
string |
Name of the carrier. |
IsInactive |
bool |
Availability flag (β active, β inactive). |
πΌ 5. UI Composition & Razor Elements
-
Layout & Title
@{ ViewData["Title"] = "Carrier Type List"; Layout = "~/Views/Shared/_ATSLayout.cshtml"; } -
Header & Badge
<h2>Carriers <span class="badge irby-red"> @Model.CarriersTypeDetail.Count() </span></h2> -
βAdd New Carrierβ Button
<a asp-action="Create" class="btn-sm btn-success irby-green"> Add New Carrier </a> -
DataTable Markup
<table id="assetDatatable" class="table table-striped table-bordered ..."> <thead> <tr> <th>Name</th> <th>Available?</th> <th>Update</th> <th>Delete</th> </tr> </thead> <tbody> @foreach (var item in Model.CarriersTypeDetail) { <tr> <td>@Html.DisplayFor(m => item.Carrier)</td> <td>@(item.IsInactive ? "β " : "β")</td> <td> <a href="@Url.Action("Edit","CarrierModels", new { id=item.Id })" class="btn-sm btn-warning"> Update <img src="~/update.png" alt="Edit" style="width:23px"/> </a> </td> <td> <a href="@Url.Action("Edit","CarrierModels", new { id=item.Id })" class="btn-sm btn-danger"> Delete <img src="~/delete.png" alt="Delete" style="width:23px"/> </a> </td> </tr> } </tbody> </table>
π§ 6. Helper Methods & Utilities
-
Html.DisplayFor
Renders a model property (e.g.,item.Carrier) with the correct HTML encoding. -
Url.Action
Generates a URL to the Edit action inCarrierModelsController. -
asp-action
Tag helper for linking to the Create action.
β οΈ 7. Error Handling & Return Types
- This view does not implement explicit error-handling logic.
- In case
Model.CarriersTypeDetailisnull, theforeachwill throw an exceptionβensure the controller populates the model. - The view returns HTML content to the browser.
π 8. API Endpoints Overview
| Button / Link | Controller | Action | Route Example |
|---|---|---|---|
| Add New Carrier | CarrierType | Create | /CarrierType/Create |
| Update (per row) | CarrierModels | Edit | /CarrierModels/Edit/{id} |
| Delete (per row) | CarrierModels | Edit | /CarrierModels/Edit/{id} |
Note: Delete is wired to
Editβlikely an oversight. A proper Delete action endpoint should be implemented.
π 9. Third-party Integrations
-
DataTables.net
- Features: sorting, search, pagination, export buttons (CSV, Excel, Print).
- CSS & JS loaded via CDN.
-
JSZip & PDFMake
- Enable on-the-fly generation of zip/excel/pdf when exporting table data.
π 10. Sample Code Blocks
DataTables Initialization
@section Scripts {
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.print.min.js"></script>
<script>
$(document).ready(function() {
$('#assetDatatable').DataTable({
dom: 'Bfrtip',
buttons: ['csv', 'excel', 'print']
});
});
</script>
}
π― 11. Usage Examples
- Navigate to the Index:
https://yourapp.com/CarrierType/Index - Add a New Carrier:
- Click Add New Carrier β Fill out the form β Submit.
- Edit/Delete a Carrier:
- Use the Update or Delete buttons in each row.
π 12. UML Sequence Diagram
sequenceDiagram
participant Browser
participant Controller as CarrierTypeController
participant View
participant DataTables
Browser->>Controller: GET /CarrierType/Index
Controller->>View: return View(model)
View->>Browser: HTML + JS (DataTable)
Browser->>DataTables: initialize('#assetDatatable')
DataTables->>Browser: Enhanced table UI
π 13. Conclusion
This Index.cshtml view is a central piece for managing carrier types in the IrbyImaging application.
- It leverages Razor for dynamic server-side rendering.
- It integrates DataTables for a rich, interactive table with export features.
- It relies on simple ASP.NET Core helpers (
Html.DisplayFor,Url.Action) to wire up CRUD functionality.
By following this documentation, developers can extend, maintain, and troubleshoot the Carrier Type List page with confidence. π