๐ Documentation: IrbyImaging/Views/FieldOffices/Index.cshtml
Purpose: Renders a dynamic, filterable, and exportable table of Field Offices within the IrbyImaging application.
๐ Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- View Model & Data Model
- Markup Structure
- Data Display & Iteration
- Actions & Routing
- Thirdโparty Integrations
- Scripts & Initialization
- Sample Usage Example
- UML Component Diagram
- Conclusion
๐ Overview & Purpose
The Index.cshtml view is responsible for displaying a comprehensive list of Field Offices in a tabular format. It:
- ๐จ Utilizes DataTables to provide sorting, paging, filtering, and export functionality.
- ๐ Shows key details for each office (JDE number, contact, managers, address).
- ๐ Offers quick navigation to Create, Details, and Update actions.
๐งฉ Key Functional Areas
| Functional Area | Description |
|---|---|
| Page Metadata | Sets the Title and Layout via ViewData and _ATSLayout.cshtml. |
| Toolbar | โAdd New Field Officeโ button for creating new entries. |
| Data Table | Table headers, rows populate from the IEnumerable<FieldOffice> model. |
| Action Links | โDetailsโ and โUpdateโ buttons with icons. |
| DataTables Integration | CSS/JS imports + initialization for export buttons (csv, excel, print). |
| Responsive Design | Uses Bootstrap 4 grid classes (row, col-lg-2). |
โ๏ธ Dependencies & Technologies
- ASP.NET Core MVC
- Razor View Engine
- jQuery 3.5.1
- DataTables (+ Buttons extension)
- Bootstrap 4
- MetisMenu, SimpleBar, Waves (interface libs)
๐พ View Model & Data Model
Model Declaration
@model IEnumerable<IrbyImaging.DomainClasses.FieldOffice>
FieldOffice Domain Class (simplified)
| Property | Type | Description |
|---|---|---|
int Id |
int | Primary key |
string JdeNumber |
string | Unique JDE office identifier |
string Name |
string | Field Office name |
Employee Manager |
Employee | Office Manager |
Employee Lead |
Employee | Office Lead |
string OfficePhone |
string | Contact phone number |
string FaxNumber |
string | Fax number |
string MailingAddress |
string | Postal address |
| ... | โฆ | Other related properties |
๐ Markup Structure
@{
ViewData["Title"] = "Field Office List";
Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
<h2>
Field Offices <span class="badge irby-blue">@Model.Count()</span>
</h2>
<div class="row">
<div class="col-lg-2">
<a asp-action="Create" class="btn btn-success irby-green">
Add New Field Office
</a>
</div>
</div>
<table id="fieldOfficesDatatable" class="table table-striped table-bordered">
<thead>โฆ</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>@item.JdeNumber</td>
<td>@item.Name</td>
โฆ action links โฆ
</tr>
}
</tbody>
</table>
- Layout & Title: Defined at the top.
- Badge: Shows real-time count:
@Model.Count(). - Commented Code: A search form and local script references are commented out (
@* ... *@).
๐ Data Display & Iteration
- Headers: Uses
@Html.DisplayNameFor(model => model.Property)for localization/friendly names. - Rows: Loops
@foreach (var item in Model)to render each Field Office. - Nested Links: Manager, Superintendent, ProjectManager, and Lead link to their respective details in
EmployeesController.
๐ Actions & Routing
| Action | Razor Tag Helpers | Generates URL |
|---|---|---|
| Create | <a asp-action="Create"> |
/FieldOffices/Create |
| Details | <a href="@Url.Action("Details","FieldOffices",new{id=item.Id})"> |
/FieldOffices/Details/{id} |
| Update/Edit | <a href="@Url.Action("Edit","FieldOffices",new{id=item.Id})"> |
/FieldOffices/Edit/{id} |
| Employee Info | <a asp-controller="Employees" asp-action="Details" asp-route-id="@item.ManagerId"> |
/Employees/Details/{employeeId} |
๐ Thirdโparty Integrations
- DataTables.net
- CSS:
<link href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css" rel="stylesheet" /> <link href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.dataTables.min.css" rel="stylesheet" /> - JS:
<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>
- CSS:
- Bootstrap 4
- MetisMenu, SimpleBar, Waves (for sidebar & effects)
๐ Scripts & Initialization
<script type="text/javascript">
$(document).ready(function () {
$('#fieldOfficesDatatable').DataTable({
dom: 'Bfrtip',
buttons: ['csv', 'excel', 'print']
});
});
</script>
- Initializes DataTable on page load.
- Enables CSV, Excel, and Print export buttons.
๐ Sample Usage Example
Controller Action (
FieldOfficesController.cs)
public async Task<IActionResult> Index()
{
var offices = await _context.FieldOffices
.Include(f => f.Manager)
.Include(f => f.Superintendent)
.Include(f => f.ProjectManager)
.Include(f => f.Lead)
.ToListAsync();
return View(offices);
}
Result: The
Indexview receives a list ofFieldOfficeobjects and renders them in the DataTable.
๐งญ UML Component Diagram
flowchart LR
A[Index.cshtml] -->|model binding| B[FieldOffice Domain Model]
A -->|links to| C[FieldOfficesController]
A -->|links to| D[EmployeesController]
A -->|includes| E[jQuery & DataTables]
A -->|styles| F[Bootstrap 4]
โ Conclusion
- Index.cshtml offers a robust, interactive list of Field Offices.
- It leverages Razor, ASP.NET Core MVC, and DataTables for a seamless user experience.
- Extensible to include search filters, additional export formats, or inline editing with minimal changes.
Happy coding! ๐