📄 Documentation: IrbyImaging/Views/Employees/Index.cshtml
An ASP.NET Core Razor View that renders a searchable, exportable list of employees using DataTables.
Table of Contents
- Overview & Purpose
- View Model & Data Model
- Dependencies & Technologies
- Key Functional Areas
- API Endpoints Overview
- Helper Methods & Utilities
- Error Handling & Return Types
- Third‑Party Integrations
- UML Class Diagram
- Sample Code Snippets
- Usage Examples
- Conclusion
1. Overview & Purpose
This Index view (Index.cshtml) displays the list of employees in a dynamic, interactive table. It is part of the Employees feature under the IrbyImaging application. Leveraging Razor syntax, ASP.NET Core tag helpers, and DataTables, it:
- Shows a count of employees.
- Renders employee properties (JDE number, names, job, status).
- Provides action links to employee details and job details.
- Enables export to CSV, Excel, and printable view.
2. View Model & Data Model
@model IEnumerable<IrbyImaging.DomainClasses.Employee>
Employee (from IrbyImaging.DomainClasses) likely contains:
| Property | Type | Description |
|---|---|---|
| EmployeeId | Guid |
Unique identifier (primary key) |
| JdeNumber | int |
Internal JDE system employee number |
| LastName | string |
Employee’s last name |
| FirstName | string |
Employee’s first name |
| MiddleName | string |
Employee’s middle name (optional) |
| JobId | Guid |
FK to Job entity |
| Status | string |
Employment status (Active/Inactive) |
| Job | Job |
Navigation property to Job details |
3. Dependencies & Technologies
| Category | Libraries / Frameworks |
|---|---|
| ASP.NET Core / Razor | Microsoft.AspNetCore.Mvc.Razor, Tag Helpers |
| CSS Framework | Bootstrap 4, Custom .irby-blue badge |
| DataTables | jQuery DataTables, Buttons (CSV, Excel, Print) |
| JavaScript | jQuery, DataTables JS, jszip, pdfmake, Buttons extensions |
| Layout | Shared layout: _ATSLayout.cshtml |
4. Key Functional Areas
4.1 Page Setup (Title & Layout)
@{
ViewData["Title"] = "Employee List";
Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
ViewData["Title"]: Sets the page title rendered in<title>.Layout: Specifies the shared layout file for consistent look/feel.
4.2 Employee Count Badge
<h2>
Employees
<span class="badge irby-blue" style="color: #495057;">
@Model.Count()
</span>
</h2>
- Displays total number of employees using
@Model.Count(). - Styled with a custom badge class
irby-blue.
4.3 Search Form (Commented)
🚧 Two versions of a search form are commented out. They hint at client‑side autocomplete logic and a “quick search” hidden-GUID approach.
@* … original form … *@
@* … autocomplete form … *@
- Intended to allow searching employees by name with jQuery UI autocomplete.
- Currently disabled; replaced by DataTables built‑in search.
4.4 DataTables Markup
<table id="employeeDatatable" class="table table-striped table-bordered dt-responsive nowrap cell-border"
width="100%" cellspacing="0">
<thead>…</thead>
<tbody>…</tbody>
</table>
id="employeeDatatable": Target for JS initialization.- Classes for responsive, striped, and bordered styling.
<thead>uses@Html.DisplayNameForto render column headers based on the model.
4.5 Data Binding & Action Links
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(m => item.JdeNumber)</td>
…
<td>
<a asp-controller="Jobs" asp-action="Details"
asp-route-id="@item.JobId">
@Html.DisplayFor(m => item.Job.Name)
</a>
</td>
<td>@Html.DisplayFor(m => item.Status)</td>
<td>
<a href="@Url.Action("Details","Employees", new { id = item.EmployeeId })"
class="btn-sm btn-danger irby-blue">
Details <img src="~/details.png" style="width:20px;" />
</a>
</td>
</tr>
}
- DisplayFor: Safely outputs each property.
- asp-controller / asp-action: Tag helpers for Jobs details link.
- Url.Action: Builds link to Employee details with
id.
4.6 Styles & Scripts Section
@section Scripts {
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<!-- DataTables core & Buttons extensions -->
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
…
<!-- Initialization -->
<script type="text/javascript">
$(document).ready(function () {
$('#employeeDatatable').DataTable({
dom: 'Bfrtip',
buttons: ['csv', 'excel', 'print']
});
});
</script>
}
- Loads jQuery and DataTables from CDNs.
- Initializes DataTable with export buttons via
dom: 'Bfrtip'.
5. API Endpoints Overview
| Action | Controller | Route | Purpose |
|---|---|---|---|
| GET /Employees/Index | Employees | /Employees |
Retrieve list of employees |
| GET /Employees/Details | Employees | /Employees/Details/{id} |
Show details for selected emp |
| GET /Jobs/Details | Jobs | /Jobs/Details/{id} |
Show job details |
| (Commented) GET /Home/GetNames | Home | /Home/GetNames |
Autocomplete source (unused) |
6. Helper Methods & Utilities
- @Html.DisplayNameFor: Dynamically reads model metadata to label columns.
- @Html.DisplayFor: Encodes and displays model property values.
- asp-route-id: Tag helper to pass route parameters.
7. Error Handling & Return Types
- This view relies on the controller to provide a valid
IEnumerable<Employee>. - No in‑view error handling; errors bubble up to the MVC pipeline.
- If
Modelisnull, a runtime exception will occur.
8. Third‑Party Integrations
| Library | Purpose |
|---|---|
| jQuery | DOM manipulation, AJAX (if needed) |
| DataTables (1.10.x) | Interactive table, pagination, search, export |
| JSZip (3.1.3) | Generate ZIP for Excel export |
| pdfmake (0.1.53) | PDF generation for print |
| Bootstrap 4 | Responsive UI components |
9. UML Class Diagram
classDiagram
class Employee {
+Guid EmployeeId
+int JdeNumber
+string LastName
+string FirstName
+string MiddleName
+Guid JobId
+string Status
}
class Job {
+Guid JobId
+string Name
+string Description
}
Employee --> Job : JobId
10. Sample Code Snippets
DataTable Initialization
$(document).ready(function () {
$('#employeeDatatable').DataTable({
dom: 'Bfrtip',
buttons: ['csv', 'excel', 'print']
});
});
Razor Loop
@foreach (var emp in Model) {
<tr>
<td>@emp.JdeNumber</td>
<td>@emp.LastName, @emp.FirstName</td>
<!-- … -->
</tr>
}
11. Usage Examples
- Navigate to /Employees.
- The view displays a table of employees with sorting, pagination, and export controls.
- Click Details to view full employee profile.
- Click a Job link to view job-specific details.
- Use the search box (built-in DataTables) to filter by name, status, or JDE number.
12. Conclusion
This Index.cshtml provides a powerful, responsive listing of employees leveraging ASP.NET Core MVC and the DataTables plugin. By combining server‑side model binding with client‑side enhancements, the page delivers:
- 📋 A clear overview of employee data
- 🔍 Instant search & filters
- 💾 Export functionality (CSV, Excel, Print)
- 🔗 Seamless navigation to detail pages
Feel free to uncomment and customize the search form or add additional columns/actions as your application requirements evolve. 🚀