πŸ“„ AssetModels/Index.cshtml Documentation


Table of Contents

  1. Introduction πŸš€
  2. Overview & Purpose 🎯
  3. File Metadata πŸ—‚οΈ
  4. Dependencies & Technologies πŸ”—
  5. Model Binding 🏷️
  6. Layout & Page Title πŸ–₯️
  7. Page Header & Actions πŸ› οΈ
  8. Data Table Structure πŸ“Š
  9. CSS & JavaScript Dependencies 🎨🧩
  10. Script Initialization & DataTable Setup βš™οΈ
  11. UML Class Diagram πŸ“
  12. Usage & Integration Example πŸ”„
  13. Potential Enhancements 🌱
  14. 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:

    1. Make (e.g. Nikon, Canon)
    2. Model Name
    3. Category (e.g. SLR, Mirrorless)
    4. Type (e.g. DSLR, Point & Shoot)
    5. Availability (βœ… / ❌)
    6. Update link
    7. 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 πŸ”„

  1. Controller:

    public class AssetModelsController : Controller
    {
        public IActionResult Index()
        {
            var assetModel = _repository.GetAllAssetModels(); // Returns AssetModel domain class
            return View(assetModel);
        }
    }
    
  2. Accessing the Page:
    Navigate to /AssetModels/Index in your browser.
    You will see the DataTable with search, pagination, and export buttons.

  3. 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! πŸŽ‰