📋 FieldOffices/Edit.cshtml Documentation
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Domain Model:
FieldOffice - View Model & Data Binding
- HTML Structure & UI Components
- Form Fields Breakdown
- Dropdown Initialization & Default Values
- Validation & Error Handling
- Scripts & Third-Party Integrations
- UML Diagrams
- Sample Usage & Code Snippets
- Conclusion
1. Overview & Purpose
File: IrbyImaging/Views/FieldOffices/Edit.cshtml
Title: Field Office Update 🔄
This Razor view renders a form to edit an existing Field Office record in the Irby Imaging application. It is part of the ASP.NET MVC UI layer, using a strongly typed model (IrbyImaging.DomainClasses.FieldOffice) to pre‑populate fields and dropdowns.
Key Goals
- Display current FieldOffice data
- Allow users to update text fields, phone numbers, addresses, and staff assignments
- Provide client‑side validation and enhanced UI widgets (Select2, datepicker, etc.)
2. Dependencies & Technologies
| Type | Library / Tool | Usage |
|---|---|---|
| CSS Framework | Bootstrap (v4/5) | Responsive grid, form styling |
| JS Utilities | jQuery | DOM manipulation |
| Select Dropdown | Select2 | Enhanced <select> inputs |
| Date Picker | bootstrap-datepicker | Date inputs (if present in other views) |
| Rich Text | TinyMCE | Loaded but not directly used here |
| File Upload | Dropzone | Styles loaded, not used in this form |
| Form Repeater | jquery.repeater | Loaded for dynamic lists, not in this form |
| Custom Layout | ~/Views/Shared/_ATSLayout.cshtml |
Application’s master page |
| Validation | _ValidationScriptsPartial |
Unobtrusive client‑side validation |
🚀 Note: Some libraries (TinyMCE, Dropzone, repeater) are included globally in the layout but are not explicitly leveraged by this view.
3. Domain Model: FieldOffice
This view uses the FieldOffice domain class. Below is a simplified representation:
namespace IrbyImaging.DomainClasses
{
public class FieldOffice
{
public int Id { get; set; }
public string JdeNumber { get; set; }
public string Name { get; set; }
// Staff assignments
public int? ManagerId { get; set; }
public Employee Manager { get; set; }
public int? ProjectManagerId { get; set; }
public Employee ProjectManager { get; set; }
public int? AsstProjectManagerId { get; set; }
public Employee AsstProjectManager { get; set; }
public int? SuperintendentId { get; set; }
public Employee Superintendent { get; set; }
public int? LeadId { get; set; }
public Employee Lead { get; set; }
public int? DirectorId { get; set; }
public Employee Director { get; set; }
public int? PrimaryContactId { get; set; }
public Employee PrimaryContact { get; set; }
public int? SecondaryContactId { get; set; }
public Employee SecondaryContact { get; set; }
// Contact info
public string OfficePhone { get; set; }
public string FaxNumber { get; set; }
public string PrimaryContactPhone { get; set; }
public string SecondaryContactPhone { get; set; }
// Addresses
public string MailingAddress { get; set; }
public string ShippingAddress { get; set; }
// Helper for dropdowns (SelectList of employees)
public IEnumerable<SelectListItem> EmployeeData { get; set; }
}
}
4. View Model & Data Binding
@model IrbyImaging.DomainClasses.FieldOffice
- Strongly‑typed view: binds directly to a
FieldOfficeobject. asp-for&asp-itemstags auto-generatenameandidattributes, and map values back to the model on form submission.- Hidden input for
Idensures the correct record is updated.
5. HTML Structure & UI Components
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<form asp-action="Edit"> ... </form>
</div>
</div>
</div>
</div>
- Bootstrap grid:
.row/.col-lg-* - Card UI: groups the form in a styled container.
- Form: posts data to the
Editaction of theFieldOfficescontroller.
6. Form Fields Breakdown
| Label | Property | Input Type | Validation |
|---|---|---|---|
| JDE Number | JdeNumber |
Text | Required? (server‑side) |
| Field Office Name | Name |
Text | Required? (server‑side) |
| Manager | ManagerId |
Select | Model.EmployeeData |
| Project Manager | ProjectManagerId |
Select | Model.EmployeeData |
| Asst PM | AsstProjectManagerId |
Select | Model.EmployeeData |
| Superintendent | SuperintendentId |
Select | Model.EmployeeData |
| Lead | LeadId |
Select | Model.EmployeeData |
| Director | DirectorId |
Select | Model.EmployeeData |
| Office Phone | OfficePhone |
Tel | Regex: [0-9]{3}-[0-9]{2}-[0-9]{3} |
| Fax Number | FaxNumber |
Tel | Regex: same as above |
| Mailing Address | MailingAddress |
Text | — |
| Shipping Address | ShippingAddress |
Text | — |
| Primary Contact | PrimaryContactId |
Select | Model.EmployeeData |
| Primary Phone | PrimaryContactPhone |
Tel | Regex: same |
| Secondary Contact | SecondaryContactId |
Select | Model.EmployeeData |
| Secondary Phone | SecondaryContactPhone |
Tel | Regex: same |
✨ Note: All <select> elements use the class .js-example-basic-single for Select2 enhancement.
7. Dropdown Initialization & Default Values
Before rendering, the view sets up placeholder texts:
@{
var mgrVal = Model.Manager?.FullName ?? "Select Manager";
var pmgrVal = Model.ProjectManager?.FullName ?? "Select Project Manager";
// ... and so on for each role
}
Each <select> begins with:
<select asp-for="ManagerId" asp-items="@Model.EmployeeData" class="js-example-basic-single">
<option>@mgrVal</option>
</select>
- If the model has a selected
Manager, their name appears; otherwise, a prompt is shown.
8. Validation & Error Handling
- Unobtrusive validation is enabled via:
@section Scripts { @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } } - Each input has a
<span asp-validation-for="..."></span>to display validation messages.
9. Scripts & Third-Party Integrations
<!-- jQuery, Bootstrap, MetisMenu, SimpleBar, Waves -->
<script src="~/libs/jquery/jquery.min.js"></script>
<script src="~/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- ... other shared libs ... -->
<!-- Select2 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<script>
$(document).ready(() => {
$('.js-example-basic-single').select2();
});
</script>
| Library | Purpose |
|---|---|
| Select2 | Searchable dropdowns |
| bootstrap-datepicker | Date selection (styles loaded) |
| TinyMCE | Rich text editor (loaded globally) |
| Dropzone | File upload UI (styles loaded) |
10. UML Diagrams
10.1 Class Diagram
classDiagram
%% Domain classes
class FieldOffice {
+int Id
+string JdeNumber
+string Name
+int? ManagerId
+int? ProjectManagerId
+...
}
class Employee {
+int Id
+string FullName
}
FieldOffice --> Employee : Manager, Lead, etc.
10.2 Sequence Diagram (Edit Flow)
sequenceDiagram
participant U as User
participant V as Edit.cshtml View
participant C as FieldOfficesController
participant M as FieldOffice Model
U->>V: Open Edit page
V->>C: GET Edit(id)
C->>M: Fetch FieldOffice
C-->>V: Return model
U->>V: Submit updated form
V->>C: POST Edit(model)
C->>M: Validate & Save
C-->>U: Redirect to Index or show errors
11. Sample Usage & Code Snippets
Rendering the View (Controller)
// GET: FieldOffices/Edit/5
public IActionResult Edit(int id)
{
var fieldOffice = _service.GetById(id);
fieldOffice.EmployeeData = GetEmployeeSelectList();
return View(fieldOffice);
}
// POST: FieldOffices/Edit
[HttpPost]
public IActionResult Edit(FieldOffice model)
{
if (!ModelState.IsValid)
{
model.EmployeeData = GetEmployeeSelectList();
return View(model);
}
_service.Update(model);
return RedirectToAction(nameof(Index));
}
Sample Razor Snippet
<div class="form-group row mb-4">
<label class="col-form-label col-sm-1"><strong>JDE Number</strong></label>
<div class="col-lg-2">
<input asp-for="JdeNumber" class="form-control" />
<span asp-validation-for="JdeNumber" class="text-danger"></span>
</div>
<!-- More fields... -->
</div>
12. Conclusion
The Edit.cshtml view is a comprehensive form for updating Field Office records within the Irby Imaging application. By leveraging ASP.NET Core’s tag helpers, robust domain classes, and popular UI libraries like Select2 and Bootstrap, it provides a user-friendly, validated interface to manage critical business data.
⭐ Key takeaways
- Strongly‑typed binding to
FieldOfficeensures compile‑time safety. - Dynamic dropdowns populated from
Model.EmployeeData. - Client‑side validation and enhanced widgets deliver a polished UX.
Happy coding! 🚀