🚢 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

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. DockEditViewModel (View Model)
  5. Helper Methods & Utilities
  6. Error Handling & Validation
  7. API Endpoints Overview
  8. Third‑party Integrations
  9. Sample Code Blocks
  10. Usage Examples
  11. UML Class Diagram
  12. 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

  1. Tag Helpers

    • asp-for — Binds an input element to model property.
    • asp-items — Populates <select> elements from an IEnumerable<SelectListItem>.
    • asp-action="Edit" — Specifies form POST target.
  2. Enum SelectList

    @Html.GetEnumSelectList<AssetStatus>()
        .Where(e => e.Text != "All")
    

    Filters out the ā€œAllā€ enum value for the status dropdown.

  3. Validation Summary

    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
    
  4. 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:
    @if (!string.IsNullOrEmpty(Model.ErrorMessage)) {
        await Html.RenderPartialAsync("_ErrorModalPartial");
    }
    
    Triggered when ErrorMessage is 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

  1. Navigating to Edit Page

    • URL: https://yourapp/Docks/Edit/5
    • Renders form pre‑populated with Dock #5 data.
  2. Submitting Updates

    • Fill fields, click Update.
    • On success → Redirect to Index or show success message.
    • On server error → ErrorMessage set 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