📱 Edit Mobile Device View Documentation (Edit.cshtml)
📑 Table of Contents
- Overview & Purpose
- Layout & Structure
- Dependencies & Technologies
- ViewModel & Data Models
- Form Fields & Data Binding
- Validation & Error Handling
- JavaScript & Client‑Side Scripts
- Sequence Diagram
- Usage Examples
- Conclusion
1. Overview & Purpose
The Edit.cshtml Razor view enables end‑users to update an existing Mobile Device asset in the IrbyImaging system. It is rendered by the MobileDevicesController.Edit actions (both GET and POST) and binds to a strongly‑typed MobileDeviceEditViewModel, showing a pre‑populated form, performing validation, and handling error scenarios gracefully.
- Location:
Views/MobileDevices/Edit.cshtml - Layout:
_ATSLayout.cshtml - ViewModel:
MobileDeviceEditViewModel - Supported HTTP Actions:
- GET – fetch existing device data
- POST – submit updates for processing
2. Layout & Structure
@model MobileDeviceEditViewModel
@{
ViewData["Title"] = "Mobile Device Update";
Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
<h2>Mobile Device Update</h2>
<h4>Asset ID: @Model.Id</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Edit">
<!-- Validation summary & Hidden fields -->
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Id" />
<!-- Form groups for each property -->
<!-- ... -->
<div class="form-group">
<a asp-action="Index" class="btn btn-danger irby-red">Index List</a>
<input type="submit" value="Update" class="btn btn-success irby-green" />
</div>
</form>
</div>
</div>
@if (!string.IsNullOrEmpty(Model.ErrorMessage)) {
await Html.RenderPartialAsync("_ErrorModalPartial");
}
@section Scripts {
@await Html.RenderPartialAsync("_ValidationScriptsPartial")
@await Html.RenderPartialAsync("_ErrorModalScriptsPartial")
}
- @model: Binds the view to
MobileDeviceEditViewModel. - Tag Helpers (
asp-for,asp-items,asp-action): Simplify form rendering and routing. - Partials:
_ValidationScriptsPartial&_ErrorModalPartialfor modular validation and error display.
3. Dependencies & Technologies
| Technology / Library | Purpose |
|---|---|
| ASP.NET Core MVC | Server‑side framework |
| Razor View Engine | Templating & layout management |
| Tag Helpers | Clean, HTML‑friendly form binding |
| Bootstrap | Responsive grid, form styling, modals |
| jQuery Unobtrusive Validation | Client‑side validation scripts |
| metisMenu, simplebar, waves | UI enhancements (sidebar, custom scrollbars, click waves) |
🎨 Styling
Custom CSS classes like.irby-redand.irby-greenadhere to the IrbyImaging brand palette.
4. ViewModel & Data Models
This view leverages a strongly‑typed ViewModel to transport data between controller and view.
public class MobileDeviceEditViewModel
{
public int Id { get; set; }
public bool IsTelogis { get; set; }
// Model selection
public int ModelId { get; set; }
public IEnumerable<SelectListItem> ModelList { get; set; }
// Device identifiers
public string SerialNumber { get; set; }
public Carrier Carrier { get; set; }
public string PhoneNumber { get; set; }
public string Imei { get; set; }
public string Sim { get; set; }
// Purchase & assignment
public DateTime? PurchaseDate { get; set; }
public int OwnerId { get; set; }
public IEnumerable<SelectListItem> OwnerList { get; set; }
// Status & review
public AssetStatus Status { get; set; }
public bool NeedsReview { get; set; }
// Additional details
public string Notes { get; set; }
public string Reason { get; set; }
// Error feedback
public string ErrorMessage { get; set; }
}
classDiagram
class MobileDeviceEditViewModel {
+int Id
+bool IsTelogis
+int ModelId
+IEnumerable<SelectListItem> ModelList
+string SerialNumber
+Carrier Carrier
+string PhoneNumber
+string Imei
+string Sim
+DateTime? PurchaseDate
+int OwnerId
+IEnumerable<SelectListItem> OwnerList
+AssetStatus Status
+bool NeedsReview
+string Notes
+string Reason
+string ErrorMessage
}
5. Form Fields & Data Binding
Each HTML input is bound via Tag Helpers:
| Label | Input Type | Tag Helpers | Validation Span |
|---|---|---|---|
| Asset ID | hidden | asp-for="Id" |
— |
| Is Telogis | checkbox | asp-for="IsTelogis" |
asp-validation-for |
| Model | dropdown | asp-for="ModelId", asp-items="ModelList" |
asp-validation-for |
| Serial Number | text | asp-for="SerialNumber" |
asp-validation-for |
| Carrier | dropdown | asp-for="Carrier", @Html.GetEnumSelectList<Carrier>() |
asp-validation-for |
| Phone Number | text | asp-for="PhoneNumber" |
asp-validation-for |
| IMEI | text | asp-for="Imei" |
asp-validation-for |
| SIM | text | asp-for="Sim" |
asp-validation-for |
| Purchase Date | text | asp-for="PurchaseDate" |
asp-validation-for |
| Owner | dropdown | asp-for="OwnerId", asp-items="OwnerList" |
asp-validation-for |
| Status | dropdown | asp-for="Status", GetEnumSelectList<AssetStatus>() (excludes “All”) |
asp-validation-for |
| Needs Review | checkbox | asp-for="NeedsReview" |
asp-validation-for |
| Notes | textarea | asp-for="Notes" |
asp-validation-for |
| Reason | textarea | asp-for="Reason" |
asp-validation-for |
🔧 Note: A commented-out
<div id="typeDiv">hints at a future feature for showing device type conditionally.
6. Validation & Error Handling
-
Server‑Side
ModelState.IsValidcheck in the controller’s POST action.- On failure: re-render the view with validation messages.
-
Client‑Side
_ValidationScriptsPartialloads- jQuery
- jQuery Validate
- jQuery Unobtrusive Validation
-
Error Modal
@if (!string.IsNullOrEmpty(Model.ErrorMessage)) { await Html.RenderPartialAsync("_ErrorModalPartial"); }- Displays any ErrorMessage in a Bootstrap modal via the
_ErrorModalPartial.
- Displays any ErrorMessage in a Bootstrap modal via the
7. JavaScript & Client‑Side Scripts
<script src="~/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/libs/metismenu/metisMenu.min.js"></script>
<script src="~/libs/simplebar/simplebar.min.js"></script>
<script src="~/libs/node-waves/waves.min.js"></script>
@section Scripts {
@await Html.RenderPartialAsync("_ValidationScriptsPartial")
@await Html.RenderPartialAsync("_ErrorModalScriptsPartial")
}
- Bootstrap Bundle: Popper.js + Bootstrap JS
- metisMenu: Sidebar toggling
- simplebar: Custom scrollbars
- waves: Click ripple effect
⚙️ Additional scripts can be added here for dynamic behaviors (e.g., toggling fields).
8. Sequence Diagram
sequenceDiagram
participant U as User (Browser)
participant C as MobileDevicesController
participant V as Edit.cshtml View
U->>C: GET /MobileDevices/Edit/{id}
C->>V: Render Edit view with populated MobileDeviceEditViewModel
U->>V: Modify form fields & click **Update**
V->>C: POST /MobileDevices/Edit (form payload)
C->>C: Validate ModelState
alt Valid Model
C->>DB: Save changes
C->>U: Redirect to **Index**
else Invalid Model
C->>V: Return view with validation errors
end
9. Usage Examples
1. Navigate to the Edit Form
GET https://yourapp.com/MobileDevices/Edit/42
2. Update a Device
- Change Carrier to “Verizon”.
- Toggle Needs Review.
- Click Update.
3. Validation Error
- Leave Serial Number empty.
- Attempt submit → client‑side highlights missing field.
- If bypassed, server‑side re‑renders with error messages.
4. Controller Snippet
[HttpPost]
public async Task<IActionResult> Edit(MobileDeviceEditViewModel model)
{
if (!ModelState.IsValid)
{
// Re-populate dropdown lists
model.ModelList = await _deviceService.GetModelSelectListAsync();
model.OwnerList = await _userService.GetOwnerSelectListAsync();
return View(model);
}
await _deviceService.UpdateDeviceAsync(model);
return RedirectToAction(nameof(Index));
}
10. Conclusion
The Edit.cshtml view is a robust, feature-rich interface for updating Mobile Device assets. It combines:
- ✅ Strongly‑typed ViewModel for clean data binding
- ✅ ASP.NET Core Tag Helpers for concise markup
- ✅ Bootstrap + jQuery for responsive styling & validation
- ✅ Partial Views for modular error & script loading
Future enhancements may include dynamic field toggles (uncommented typeDiv) or richer client‑side interactions via Vue/React or more advanced validation.
End of Edit.cshtml documentation 🎉