π Documentation: CostCodeUpload.cshtml
π Table of Contents
- π― Overview & Purpose
- π Key Functional Areas
- π§ Dependencies & Technologies
- π¦ Models & ViewModels
- πΌ UI Layout & Structure
- π Forms & Data Binding
- π» Client-Side Logic & Helpers
- π¨ Error Handling & Validation
- π Third-Party Integrations
- π‘ Sample Usage & Code Snippets
- π UML Sequence Diagram
- β Conclusion
π― Overview & Purpose
CostCodeUpload.cshtml is an ASP.NET Core Razor View that enables users to upload and submit new cost codes associated with mechanic timesheets. It provides:
- A form to enter Cost Code and Cost Code Name
- A Syncfusion ComboBox to select a Current Job from a dynamic list
- A Bootstrap Modal for Preview & Confirmation before final submission
This page is part of the TimeEntry workflow in the IrbyImaging application, specifically under FringeBenefits.
π Key Functional Areas
| Section | Description |
|---|---|
| Header & Layout | Sets the page title and uses the _TimeLayout.cshtml master layout. |
| Styles & Scripts | Includes CSS/JS for Syncfusion, Bootstrap, DataTables, jQuery, etc. |
| Cost Code Form | Inputs for Cost Code, Cost Code Name, and Job selection. |
| Confirmation Modal | Preview of entered data with Ok / Cancel controls. |
| Client-Side Validation | Ensures all fields are filled before showing the modal. |
| Form Submission | Posts data to TimeEntryController.CostCodeUpload via HTTP POST after confirmation. |
π§ Dependencies & Technologies
| Category | Library / Framework | Purpose |
|---|---|---|
| ASP.NET Core MVC | Razor Views (.cshtml) |
Server-side rendering & binding |
| Styling | Bootstrap 4 | Layout, grid, modal |
| UI Components | Syncfusion EJ2 (ComboBox) | Rich dropdown with filtering |
| DataTables | DataTables.net (JS + CSS) | (Not used directly here but available) |
| JavaScript Library | jQuery 3.6 | DOM manipulation & event handling |
| Modal | Bootstrap Modal | Preview & confirmation UI |
| JSON Serialization | Newtonsoft.Json | (Available for server-side needs) |
π¦ Models & ViewModels
@model IrbyImaging.DomainClasses.MechanicTimesheet
- Model:
MechanicTimesheetβthe domain class backing the view; though only cost code fields are used here - ViewBag:
ViewBag.Jobsβa list of{ Text, Value }pairs used as the data source for the Syncfusion ComboBox
πΌ UI Layout & Structure
@{
ViewData["Title"] = "Cost Code Upload";
Layout = "~/Views/Shared/_TimeLayout.cshtml";
}
<h2>Cost Code Upload</h2>
- Layout: Sections of header, sidebar, footer are inherited from
_TimeLayout.cshtml - Title: Dynamically set to βCost Code Uploadβ
Grid Structure
<div class="card">
<div class="card-body">
<div class="row">
<!-- Left Column: Cost Code -->
<div class="col-lg-2"> β¦ </div>
<!-- Right Column: Cost Code Name -->
<div class="col-lg-2"> β¦ </div>
</div>
<div class="row mt-2">
<!-- Job ComboBox -->
<div class="col-lg-4"> β¦ </div>
</div>
<div class="row mt-2">
<!-- Submit Button -->
<div class="col"> β¦ </div>
</div>
</div>
</div>
- Uses Bootstrap grid for responsive two-column input layout and full-width button
π Forms & Data Binding
<form asp-action="CostCodeUpload" asp-controller="TimeEntry" method="post">
@Html.AntiForgeryToken()
<!-- Cost Code Field -->
<input type="number" id="costCode" name="costCode" required />
<!-- Cost Code Name Field -->
<input type="text" id="costCodeName" name="costCodeName" required />
<!-- Syncfusion ComboBox for Job Selection -->
<ejs-combobox
id="jobCombo"
dataSource="@(ViewBag.Jobs)"
placeholder="Select a job"
popupHeight="330px"
allowFiltering="true"
filterType="Contains"
change="valueChange">
<e-combobox-fields text="Text" value="Value"></e-combobox-fields>
</ejs-combobox>
<input type="hidden" id="jobId" name="jobId" required />
<!-- Preview Button (manual click triggers modal) -->
<button type="button" id="previewButton" class="btn btn-primary">
Submit
</button>
</form>
- Anti-forgery token for CSRF protection
- Hidden
jobIdfield updated via Syncfusionchangeevent
π» Client-Side Logic & Helpers
$(document).ready(function () {
// 1οΈβ£ Preview Button Click
$('#previewButton').click(function() {
if (!validateForm()) {
alert('Please fill in all required fieldsβ¦');
return;
}
// Populate Modal
$('#modalCostCode').text($('#costCode').val());
$('#modalCostCodeName').text($('#costCodeName').val());
var combo = document.getElementById('jobCombo').ej2_instances[0];
$('#modalJob').text(combo.text);
// Show Bootstrap Modal
new bootstrap.Modal($('#confirmationModal')).show();
});
// 2οΈβ£ Confirm & Submit
$('#confirmSubmit').click(function() {
$('form').submit();
});
// Validation Helper
function validateForm() {
return $('#costCode').val() && $('#costCodeName').val() && $('#jobId').val();
}
});
// Syncfusion ComboBox Change Event
function valueChange() {
var combo = document.getElementById('jobCombo').ej2_instances[0];
document.getElementById('jobId').value = combo.value;
}
- validateForm(): Ensures Cost Code, Name, and Job are selected
- valueChange(): Binds ComboBox selection to the hidden
jobIdinput
π¨ Error Handling & Validation
- HTML
requiredattributes on inputs - JavaScript
validateForm(): alerts if any field is empty - Anti-forgery token to prevent CSRF
- Server-side (controller) should re-validate fields before persisting
π Third-Party Integrations
- Syncfusion EJ2
- ComboBox: rich dropdown with built-in filtering, templating
- Bootstrap
- Modal, grid system, buttons
- DataTables & Dropzone
- Included but not actively used in this view (future extension)
π‘ Sample Usage & Code Snippets
1. Posting from Controller
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult CostCodeUpload(int costCode, string costCodeName, int jobId) {
// 1. Validate inputs
if (jobId <= 0) { ModelState.AddModelError("", "JobId is required."); }
if (!ModelState.IsValid) {
// Reload ViewBag.Jobs & return view
}
// 2. Save to database (e.g. MechanicTimesheet)
_db.MechanicTimesheets.Add(new MechanicTimesheet {
CostCode = costCode,
CostCodeName = costCodeName,
JobId = jobId
});
_db.SaveChanges();
// 3. Redirect or display success
return RedirectToAction("Index");
}
2. Populating ViewBag.Jobs
var jobs = _db.Jobs
.Select(j => new { Text = j.Name, Value = j.Id })
.ToList();
ViewBag.Jobs = jobs;
return View();
π UML Sequence Diagram
sequenceDiagram
participant U as User
participant V as CostCodeUpload View
participant C as TimeEntryController
U->>V: Fill Cost Code & Name
U->>V: Select Job (Syncfusion ComboBox)
U->>V: Click "Submit"
V->>V: validateForm()
V->>V: Show Confirmation Modal
U->>V: Click "Ok"
V->>C: HTTP POST /TimeEntry/CostCodeUpload
C-->>V: Return Redirect or View
β Conclusion
The CostCodeUpload.cshtml view provides a user-friendly, interactive interface for adding cost codes to mechanic timesheets. Leveraging Syncfusion for rich UI controls and Bootstrap for responsive layout, it guides users through:
- Entering cost code details
- Previewing their entries
- Confirming before submission
This pattern enhances data accuracy and reduces input errors. By following the documented patterns, you can extend or maintain this pageβadding further validation, custom styling, or new fieldsβwhile keeping consistency across the IrbyImaging application.