📄 Edit.cshtml Documentation
Location:
IrbyImaging/Views/GLType/Edit.cshtml
Purpose: Razor view for editing a General Ledger Type (GLType) entity.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Model & ViewData
- Layout & Page Title
- Form Structure & Key Fields
- Validation & Error Handling
- Styling & CSS Classes
- Navigation & Actions
- UML Class Diagram
- Usage Example
- Potential Enhancements
- Conclusion
🎯 Overview & Purpose
The Edit.cshtml view enables users to update an existing General Ledger Type record. It renders an HTML form with three primary fields:
- Code (string)
- Description (string)
- IsInactive (bool)
Upon submission, the form posts back to the Edit action of the GLType controller.
🛠 Dependencies & Technologies
| Technology | Version / Details |
|---|---|
| ASP.NET Core MVC | Tag Helpers (asp-for, asp-action) |
| Razor View Engine | *.cshtml syntax |
| jQuery Validation | Client-side validation via asp-validation-for |
| Bootstrap 3/4 | .form-group, .btn, grid system |
🧩 Model & ViewData
@model IrbyImaging.DomainClasses.GeneralLedger
@{
ViewData["Title"] = "Edit";
}
- Model
IrbyImaging.DomainClasses.GeneralLedger- Contains properties:
Code,Description,IsInactive, plus any other ledger metadata.
- ViewData["Title"]
- Used by the shared layout (
_ATSLayout.cshtml) to set the page title.
- Used by the shared layout (
🏗 Layout & Page Title
Layout = "~/Views/Shared/_ATSLayout.cshtml";
<h2>New Carrier</h2>
<hr />
- Layout
- Inherits header, footer & navigation from
_ATSLayout.cshtml.
- Inherits header, footer & navigation from
- Page Heading
- Displays “New Carrier”.
- ❗ Tip: Consider renaming to “Edit General Ledger Type” for clarity.
📝 Form Structure & Key Fields
<form asp-action="Edit">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<!-- Code Field -->
<div class="form-group">
<label asp-for="Code" class="control-label"></label>
<input asp-for="Code" id="typeVal" class="form-control" />
<span asp-validation-for="Code" class="text-danger"></span>
</div>
<!-- Description Field -->
<div class="form-group">
<label asp-for="Description" class="control-label"></label>
<input asp-for="Description" id="typeVal" class="form-control" />
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<!-- IsInactive Checkbox -->
<div class="form-group">
<label asp-for="IsInactive" class="control-label">Is Option Available?</label>
<input asp-for="IsInactive" id="typeVal" class="checkbox-inline" />
<span asp-validation-for="IsInactive" class="text-danger"></span>
</div>
<!-- Buttons -->
<div class="form-group">
<a asp-action="Index" class="btn btn-danger irby-red">Index List</a>
<input type="submit" value="Create" class="btn btn-success irby-green" />
</div>
</form>
Key Notes:
- asp-for
- Generates
name,idandvaluebased on model metadata.
- Generates
- asp-validation-for & asp-validation-summary
- Display server & client-side validation messages.
- id="typeVal"
- ❗ Duplicate IDs on multiple fields—consider using unique IDs or omit manual
id.
- ❗ Duplicate IDs on multiple fields—consider using unique IDs or omit manual
⚠️ Validation & Error Handling
- Client-Side
- Built-in jQuery Unobtrusive Validation uses
data-val-*attributes.
- Built-in jQuery Unobtrusive Validation uses
- Server-Side
- In the controller’s
Edit(GeneralLedger model)POST action:if (!ModelState.IsValid) { return View(model); } // ... update logic
- In the controller’s
- Error Summary
<div asp-validation-summary="ModelOnly" />shows model‑level errors.
🎨 Styling & CSS Classes
| Class Name | Purpose |
|---|---|
.form-group |
Bootstrap container for label + input + help |
.control-label |
Bootstrap label styling |
.form-control |
Standard input styling |
.btn |
Base button styles |
.btn-success |
Green “submit” button |
.btn-danger |
Red “cancel/index” button |
.irby-red |
Custom red accent |
.irby-green |
Custom green accent |
🔗 Navigation & Actions
- Back to Index
<a asp-action="Index">Index List</a>- Routes to
GLTypeController.Index()action.
- Submit
<input type="submit" value="Create" />- Posts to
GLTypeController.Edit(GeneralLedger model).
🧩 UML Class Diagram
classDiagram
class GeneralLedger {
+int Id
+string Code
+string Description
+bool IsInactive
+DateTime CreatedOn
+DateTime? ModifiedOn
}
GeneralLedger <|-- GLTypeController : uses
🚀 Usage Example
- Navigate to
/GLType/Edit/5 - Edit the Code, Description, or toggle Is Option Available?
- Submit the form.
- On success, redirect to the Index list.
Controller Snippet
public class GLTypeController : Controller
{
// GET: /GLType/Edit/5
public IActionResult Edit(int id)
{
var model = _dbContext.GeneralLedgers.Find(id);
if (model == null) return NotFound();
return View(model);
}
// POST: /GLType/Edit
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit(GeneralLedger model)
{
if (!ModelState.IsValid) return View(model);
_dbContext.Update(model);
_dbContext.SaveChanges();
return RedirectToAction(nameof(Index));
}
}
💡 Potential Enhancements
- ✅ Unique IDs: Remove duplicate
id="typeVal"or dynamically generate IDs. - ✅ Dynamic Title: Change
<h2>to@ViewData["Title"]for consistency. - ✅ Localization: Use resource files for labels & buttons.
- ✅ AJAX Submit: Provide inline validation without full page reload.
🏁 Conclusion
This Edit.cshtml view is a concise, Bootstrap-based form to update General Ledger Types. It leverages ASP.NET Core MVC Tag Helpers for rapid development, client/server validation, and consistent styling through a shared layout. Implementing the suggested enhancements will improve accessibility, maintainability, and user experience.
Happy Coding! 🚀