πŸ“„ ShowAssets.cshtml Documentation

Path: IrbyImaging/Views/ATSHome/ShowAssets.cshtml
Purpose: Render an interactive, filterable, sortable grid of assets per employee using Syncfusion EJ2 within an ASP.NET MVC Razor view.


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Models & Data Models
  4. Layout & Razor Setup
  5. Key Functional Areas
    5.1. CSS Custom Styles
    5.2. Razor Markup & Data Binding
    5.3. Syncfusion Grid Configuration
    5.4. Client-Side Scripting
  6. Third-Party Integrations
  7. Sample Code Blocks & Usage Examples
  8. UML Diagram
  9. Conclusion & Best Practices

1. Overview & Purpose

This Razor view displays a Total Assets View using the Syncfusion EJ2 Grid component. It allows end-users to:

  • πŸ“Š Sort, group, and filter asset data.
  • πŸ“‹ Add, edit, and delete asset records inline.
  • πŸ“„ Export the grid to Excel or PDF.
  • πŸ” Search and clear search criteria.

The view is backed by an AssetsView model and binds a server-side data source via ViewBag.datasource.


2. Dependencies & Technologies

Technology / Package Purpose
ASP.NET MVC Razor Server-side view engine
Syncfusion.EJ2 (NuGet) Rich JavaScript UI components (Grid, Button, etc.)
Syncfusion.JavaScript.Models Grid settings, filtering, editing configurations
Bootstrap 4 (assumed) Card layouts & responsive grid
JavaScript / ES6 Client-side event handling and grid API usage

3. View Models & Data Models

@model IrbyImaging.UI.Models.AssetsView
  • AssetsView
    • Holds all properties required by the view (e.g., a collection of asset records).
    • Typically contains a List<AssetDto> or similar in Assets property.
  • ViewBag.datasource
    • Populated by the controller action (e.g., ATSHomeController.ShowAssets) with the data to bind into the grid.

4. Layout & Razor Setup

@{
    ViewData["Title"] = "Assets List";
    Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
  • ViewData["Title"]: Sets the page title to "Assets List".
  • Layout: Uses the shared _ATSLayout.cshtml for site-wide header/footer styling.

5. Key Functional Areas

5.1 CSS Custom Styles

Customizes the look-and-feel of the Syncfusion grid:

<style>
  .e-grid .e-gridheader { border:2px solid black; }
  .e-grid .e-headercell { color: darkblue; }
  .e-grid .e-sortnumber { background-color: #deecf9; font-family: cursive; }
  /* ... More custom styles for grouping, icons, row expand/collapse ... */
</style>
  • .e-gridheader: Adds a bold border.
  • .e-headercell: Applies a dark-blue header font.
  • .e-sortnumber: Styles the sorting index badges.

5.2 Razor Markup & Data Binding

<h2>Total Assets View</h2>
<div class="card">
  <div class="card-body">
    <div id="ControlRegion">
      <h4 class="card-title mb-4">Assets Per Employee:</h4>
      <ejs-button id="clear" content="Clear Search"></ejs-button>
      <ejs-grid id="Grid"
                dataSource="@ViewBag.datasource"
                allowSorting="true" allowGrouping="true"
                allowFiltering="true" allowPaging="true"
                allowRowDragAndDrop="true"
                allowExcelExport="true" allowPdfExport="true"
                toolbar="@( new List<string> { "ExcelExport", "PdfExport", "Search" } )"
                toolbarClick="toolbarClick">
        <!-- Column definitions here -->
      </ejs-grid>
    </div>
  </div>
</div>
  • ejs-button: A Syncfusion button widget for Clear Search.
  • ejs-grid: The core grid widget, bound to server data.

5.3 Syncfusion Grid Configuration

Column Definitions

Field Header Text Width Align Notes
EmployeeNumber Employee# 70 Center PrimaryKey
EmployeeName Name 110 Left
EmploymentStatus Status 70 Center
Title Job Title 110 Left
Type Asset Type 70 Left
Category Category 75 Left
ModelName Model 110 Left
PhoneNumber Phone# 80 Center
AssetNumber Asset# 110 Center
SerialNumber Serial# 110 Left
Status Asset Status 75 Center
IsTelogis Is Telogis 70 Left Boolean indicator

Editing & Filtering

<e-grid-filterSettings type="Excel"></e-grid-filterSettings>
<e-grid-editSettings allowAdding="true"
                     allowEditing="true"
                     allowDeleting="true"
                     edit-mode="@(EditMode.Normal)">
</e-grid-editSettings>
  • FilterSettings: Uses Excel-like filter UI.
  • EditSettings: Enables inline Add / Edit / Delete functionality.

5.4 Client-Side Scripting

// Clear Search Button Handler
document.getElementById('clear').addEventListener('click', () => {
  let grid = document.getElementById("Grid").ej2_instances[0];
  grid.searchSettings.key = '';
});

// Toolbar Export Handlers
function toolbarClick(args) {
  let grid = document.getElementById("Grid").ej2_instances[0];
  if (args.item.id === 'Grid_excelexport') {
    grid.excelExport();
  }
  if (args.item.id === 'Grid_pdfexport') {
    grid.pdfExport();
  }
}
  • Clear Search: Resets the searchSettings.key to ''.
  • toolbarClick: Single function handles both Excel and PDF exports (merge both conditions).

Note: In original code there were two identical toolbarClick functions; only the latter takes effect. They have been merged here for clarity.


6. Third-Party Integrations

  • Syncfusion EJ2: Provides ejs-grid, ejs-button, and rich data operations.
  • Bootstrap (assumed): Grid layout and card components for responsive design.

7. Sample Code Blocks & Usage Examples

7.1 Controller Action

public ActionResult ShowAssets()
{
    var model = new AssetsView {
        Assets = assetService.GetAllAssets()  // returns List<AssetDto>
    };
    ViewBag.datasource = model.Assets;
    return View(model);
}

7.2 Initializing the View

@model IrbyImaging.UI.Models.AssetsView
@{ ViewData["Title"] = "Assets List"; }
@* ... Grid markup as shown above ... *@

7.3 Triggering Export

  1. Click Excel icon in toolbar β†’ grid.excelExport()
  2. Click PDF icon in toolbar β†’ grid.pdfExport()
  3. Search field filters rows on-the-fly.
  4. Clear Search resets all filters.

8. UML Diagram

 ___________________________
|       ShowAssets.cshtml   |
|---------------------------|
| <<Razor View>>            |
| - ViewBag.datasource      |
| - ejs-grid                |
| - ejs-button              |
| - CSS + JS handlers       |
|___________________________|
            |
            | uses
            v
 ___________________________
|      AssetsView Model     |
|---------------------------|
| - List<AssetDto> Assets   |
| - PagingInfo? etc.        |
|___________________________|

9. Conclusion & Best Practices

  • βœ… Modular: Clear separation of markup, styling, and script.
  • ✨ Rich UI: Syncfusion EJ2 grid provides built-in paging, filtering, grouping, editing, and export.
  • πŸ”§ Enhancements:
    • Merge duplicate toolbarClick functions.
    • Handle errors in export callbacks.
    • Add user notifications on export completion/failure.
  • πŸ“š Next Steps:
    • Integrate server-side paging for large datasets.
    • Enhance accessibility (ARIA attributes).
    • Add unit/integration tests for grid operations.

β€œWith a few lines of Razor and Syncfusion’s powerful grid, you have a fully interactive dashboard for managing employee assets!” πŸš€