π AssetModels/Index.cshtml Documentation
Table of Contents
- Introduction π
- Overview & Purpose π―
- File Metadata ποΈ
- Dependencies & Technologies π
- Model Binding π·οΈ
- Layout & Page Title π₯οΈ
- Page Header & Actions π οΈ
- Data Table Structure π
- CSS & JavaScript Dependencies π¨π§©
- Script Initialization & DataTable Setup βοΈ
- UML Class Diagram π
- Usage & Integration Example π
- Potential Enhancements π±
- Conclusion β
1. Introduction π
This documentation covers the Index.cshtml Razor view under IrbyImaging/Views/AssetModels. It's part of an ASP.NET Core MVC application for managing Asset Models. The view displays a paginated, searchable, and exportable list of asset models using the DataTables jQuery plugin.
2. Overview & Purpose π―
-
What it does
- Renders a table of existing asset models, including columns like Make, Name, Category, Type, availability, and action links.
- Integrates DataTables for sorting, searching, pagination, and exporting (CSV, Excel, Print).
-
Intended Use
- Asset Model administrators can view, add, update, and delete records in a user-friendly interface.
- Supports quick exports for reporting and offline analysis.
3. File Metadata ποΈ
| Property | Value |
|---|---|
| Path | Views/AssetModels/Index.cshtml |
| Model | IrbyImaging.DomainClasses.AssetModel |
| Layout | ~/Views/Shared/_ATSLayout.cshtml |
| Title | Asset Model List |
| Framework | ASP.NET Core MVC β |
4. Dependencies & Technologies π
| Category | Technology / Library |
|---|---|
| UI Framework | Bootstrap 4 |
| JS Plugin | jQuery, DataTables, DataTables Buttons extension |
| Data Export | JSZip, pdfmake, vfs_fonts |
| ASP.NET Core | Tag Helpers (asp-action), Razor Views |
5. Model Binding π·οΈ
@model IrbyImaging.DomainClasses.AssetModel
- Model Type:
AssetModel - Key Property:
AssetsModelDetailβ a collection of detailed asset model records.
6. Layout & Page Title π₯οΈ
@{
ViewData["Title"] = "Asset Model List";
Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
- ViewData["Title"] sets the page title.
- Layout specifies the shared layout for consistent header, footer, and styling.
7. Page Header & Actions π οΈ
<h2>
Asset Models <span class="badge irby-red">@Model.AssetsModelDetail.Count()</span>
</h2>
<p>
<a asp-action="Create" class="btn-sm btn-success irby-green">
β Add New Model
</a>
</p>
- Heading shows βAsset Modelsβ plus a badge with the total count.
- βAdd New Modelβ button uses an ASP.NET Core Tag Helper (
asp-action="Create") to link to the Create action.
8. Data Table Structure π
<table id="assetDatatable" class="table table-striped table-bordered dt-responsive nowrap">
<thead>
<tr>
<th>Make</th>
<th>Name</th>
<th>Category</th>
<th>Type</th>
<th>Available?</th>
<th>Update</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.AssetsModelDetail)
{
<tr>
<td>@Html.DisplayFor(m => item.Make.Name)</td>
<td>@Html.DisplayFor(m => item.Name)</td>
<td>@Html.DisplayFor(m => item.Category)</td>
<td>@Html.DisplayFor(m => item.Type)</td>
<td>@(item.IsAvailableOption ? "β
" : "β")</td>
<td>
<a asp-controller="AssetModels" asp-action="Edit" asp-route-id="@item.Id" class="btn-sm btn-warning">
βοΈ Update
</a>
</td>
<td>
<a asp-controller="AssetModels" asp-action="Delete" asp-route-id="@item.Id" class="btn-sm btn-danger">
ποΈ Delete
</a>
</td>
</tr>
}
</tbody>
</table>
-
Columns:
- Make (e.g. Nikon, Canon)
- Model Name
- Category (e.g. SLR, Mirrorless)
- Type (e.g. DSLR, Point & Shoot)
- Availability (β / β)
- Update link
- Delete link
-
Action Links use Tag Helpers (
asp-controller,asp-action,asp-route-id) for clean URL generation.
9. CSS & JavaScript Dependencies π¨π§©
CSS Includes
<link href="~/lib/datatables/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.dataTables.min.css" />
JavaScript Includes
<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>
10. Script Initialization & DataTable Setup βοΈ
<script type="text/javascript">
$(document).ready(function () {
$('#assetDatatable').DataTable({
dom: 'Bfrtip',
buttons: ['csv', 'excel', 'print']
});
});
</script>
dom: 'Bfrtip'places Buttons at the top (B), filter (f), table (t), information (i), and pagination (p).- Buttons: Export to CSV, Excel, and Print view.
11. UML Class Diagram π
classDiagram
AssetModel "1" o-- "*" AssetModelDetail : contains
AssetModelDetail : int Id
AssetModelDetail : Make Make
AssetModelDetail : string Name
AssetModelDetail : string Category
AssetModelDetail : string Type
AssetModelDetail : bool IsAvailableOption
class Make {
+string Name
}
12. Usage & Integration Example π
-
Controller:
public class AssetModelsController : Controller { public IActionResult Index() { var assetModel = _repository.GetAllAssetModels(); // Returns AssetModel domain class return View(assetModel); } } -
Accessing the Page:
Navigate to/AssetModels/Indexin your browser.
You will see the DataTable with search, pagination, and export buttons. -
Adding a New Model:
- Click β Add New Model
- Fill in the form at
/AssetModels/Create - Submit to return to Index with updated list.
13. Potential Enhancements π±
- ServerβSide Processing
- For large datasets, implement DataTables server-side paging/filtering.
- Confirmation Dialogs
- Add a modal confirmation for the Delete action.
- Role-Based UI
- Show/hide Update/Delete buttons based on user permissions.
- Custom Filters
- Provide dropdown filters for Make, Category, etc.
14. Conclusion β
The AssetModels/Index.cshtml view delivers a powerful, responsive, and user-friendly interface for managing asset model records. By combining ASP.NET Core MVC and DataTables, it offers built-in sorting, searching, pagination, and export capabilitiesβperfect for any administrative dashboard.
Feel free to extend with server-side processing, user-role controls, or custom styling to fit your brand!
Happy Coding! π