š¢ Edit Dock View (Edit.cshtml) Documentation
Welcome to the comprehensive documentation for IrbyImaging/Views/Docks/Edit.cshtml, the Razor view responsible for rendering the "Dock Update" form in the IrbyImaging application. This document covers everything from setup and dependencies to view models, helpers, thirdāparty integrations, and usage examples.
š Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- DockEditViewModel (View Model)
- Helper Methods & Utilities
- Error Handling & Validation
- API Endpoints Overview
- Thirdāparty Integrations
- Sample Code Blocks
- Usage Examples
- UML Class Diagram
- Conclusion
1. Overview & Purpose
File: IrbyImaging/Views/Docks/Edit.cshtml
Responsibility: Renders a Dock Update form allowing users to edit properties of a Dock asset (model, serial number, purchase date, owner, status, notes, and reason).
Intended Use: This Razor view is part of the Docks controller in an ASP.NET Core MVC application. It displays preāpopulated fields from the DockEditViewModel and submits updated data back to the server.
2. Key Functional Areas
| Section | Description |
|---|---|
| Page Setup | Sets page title and layout. |
| Header Rendering | Displays form heading and asset ID. |
| Form Fields | Binds form inputs to the view model (asp-for). |
| Validation & Error Summary | Displays client/server validation errors. |
| Action Buttons | āIndex Listā (navigation) & āUpdateā (submit). |
| Conditional Error Modal | Renders error modal partial if ErrorMessage exists. |
| Script Inclusions | Loads Bootstrap, MetisMenu, SimpleBar, Waves and validation scripts. |
3. Dependencies & Technologies
- ASP.NET Core MVC
- Razor View Engine
- Tag Helpers:
asp-for,asp-items,asp-action, etc. - Clientāside Validation: jQuery unobtrusive validation
- CSS Framework: Bootstrap
- Menu & UI Plugins: MetisMenu, SimpleBar, NodeāWaves
4. DockEditViewModel (View Model)
The view is strongly typed to DockEditViewModel. This view model carries all data needed to render and process the form.
public class DockEditViewModel
{
public int Id { get; set; }
public int ModelId { get; set; }
public IEnumerable<SelectListItem> ModelList { get; set; }
public string SerialNumber { get; set; }
public DateTime PurchaseDate { get; set; }
public int OwnerId { get; set; }
public IEnumerable<SelectListItem> OwnerList { get; set; }
public AssetStatus Status { get; set; }
public string Notes { get; set; }
public string Reason { get; set; }
public string ErrorMessage { get; set; }
}
| Property | Type | Purpose |
|---|---|---|
Id |
int | Dockās unique identifier. |
ModelId |
int | Selected dock model ID. |
ModelList |
IEnumerable | Dropdown options for dock models. |
SerialNumber |
string | Unique serial number of the dock. |
PurchaseDate |
DateTime | Date when the dock was purchased. |
OwnerId |
int | Selected owner ID. |
OwnerList |
IEnumerable | Dropdown options for owners. |
Status |
AssetStatus (enum) | Current asset status (Active, Inactive, etc.). |
Notes |
string | Optional notes. |
Reason |
string | Reason for status change or update. |
ErrorMessage |
string | Used to trigger and populate error modal. |
5. Helper Methods & Utilities
-
Tag Helpers
asp-forā Binds an input element to model property.asp-itemsā Populates<select>elements from anIEnumerable<SelectListItem>.asp-action="Edit"ā Specifies form POST target.
-
Enum SelectList
@Html.GetEnumSelectList<AssetStatus>() .Where(e => e.Text != "All")Filters out the āAllā enum value for the status dropdown.
-
Validation Summary
<div asp-validation-summary="ModelOnly" class="text-danger"></div> -
Partials
_ValidationScriptsPartialā Loads jQuery validation scripts._ErrorModalPartial&_ErrorModalScriptsPartialā Renders a modal for server errors.
6. Error Handling & Validation
- Clientāside: jQuery Unobtrusive validation powered by
data-val-*attributes autoāinserted via Tag Helpers. - Serverāside: ModelState checks in controller; invalid models reārender this view with validation messages.
- Error Modal:
Triggered when@if (!string.IsNullOrEmpty(Model.ErrorMessage)) { await Html.RenderPartialAsync("_ErrorModalPartial"); }ErrorMessageis populated by the controller (e.g., on save exceptions).
7. API Endpoints Overview
| HTTP Method | Route | Controller Action | Purpose |
|---|---|---|---|
| GET | /Docks/Edit/5 | Edit(int id) |
Retrieve edit form with data. |
| POST | /Docks/Edit | Edit(DockEditViewModel model) |
Save updates & redirect. |
8. Thirdāparty Integrations
| Library | Purpose | Source Path |
|---|---|---|
| Bootstrap | CSS framework & JS components | ~/libs/bootstrap/js/bootstrap.bundle.min.js |
| MetisMenu | Sidebar menu plugin | ~/libs/metismenu/metisMenu.min.js |
| SimpleBar | Custom scrollbars | ~/libs/simplebar/simplebar.min.js |
| NodeāWaves | Click effect for buttons | ~/libs/node-waves/waves.min.js |
9. Sample Code Blocks
Full Form Markup
<form asp-action="Edit">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Id" />
<div class="form-group">
<label asp-for="ModelId" class="control-label"></label>
<select asp-for="ModelId" class="form-control" asp-items="Model.ModelList"></select>
<span asp-validation-for="ModelId" class="text-danger"></span>
</div>
<!-- Repeat for SerialNumber, PurchaseDate, OwnerId, Status, Notes, Reason -->
<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>
Enum Dropdown Binding
<select asp-for="Status" class="form-control"
asp-items="@(Html.GetEnumSelectList<AssetStatus>()
.Where(e => e.Text != \"All\"))">
</select>
10. Usage Examples
-
Navigating to Edit Page
- URL:
https://yourapp/Docks/Edit/5 - Renders form preāpopulated with Dock #5 data.
- URL:
-
Submitting Updates
- Fill fields, click Update.
- On success ā Redirect to Index or show success message.
- On server error ā
ErrorMessageset by controller ā Modal appears.
11. UML Class Diagram
classDiagram
class DockEditViewModel {
+int Id
+int ModelId
+IEnumerable<SelectListItem> ModelList
+string SerialNumber
+DateTime PurchaseDate
+int OwnerId
+IEnumerable<SelectListItem> OwnerList
+AssetStatus Status
+string Notes
+string Reason
+string ErrorMessage
}
class AssetStatus {
<<enumeration>>
Active
Inactive
Retired
All
}
DockEditViewModel --> AssetStatus
12. Conclusion
This Edit.cshtml view provides a robust, userāfriendly interface for modifying Dock assets. By leveraging ASP.NET Coreās Razor engine, Tag Helpers, and builtāin validation, it offers:
- Stronglyātyped binding to
DockEditViewModel. - Consistent styling via Bootstrap and Irbyāspecific CSS classes.
- Dynamic dropdowns for models, owners, and status enums.
- Error handling through validation summaries and a modal popup.
- Modular script loading for performance and maintenance.
Whether youāre extending asset management features or customizing UI workflows, this view acts as a solid foundation. Happy coding! š
End of Documentation