Fix: Categories Edit form model binding with explicit attributes

**Issue**: Edit category form not displaying existing values and not updating
- Form fields were empty when loading edit page
- Submitting changes had no effect on the category

**Root Cause**:
- Edit view used asp-for helpers which don't bind properly in production
- Create view used explicit name/id attributes which work reliably
- Model values weren't being rendered in the form fields

**Solution**:
- Changed from asp-for helpers to explicit name/id attributes
- Added value="@Model.Name" to populate name input
- Added @Model.Description between textarea tags
- Changed checkbox to @(Model.IsActive ? "checked" : "")
- Matches the working pattern from Create.cshtml

**Files Changed**:
- LittleShop/Areas/Admin/Views/Categories/Edit.cshtml
  - Line 29: Input with value="@Model.Name"
  - Line 35: Textarea with @Model.Description content
  - Line 41: Checkbox with @(Model.IsActive ? "checked" : "")

**Testing**:
- Deployed to production (container: f86abfb2334b, healthy)
- Form now displays existing category values
- Updates save correctly to database

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
SysAdmin 2025-10-03 13:24:29 +01:00
parent 8a3341b59f
commit 125513dbc6

View File

@ -25,21 +25,21 @@
}
<div class="mb-3">
<label asp-for="Name" class="form-label">Name</label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
<label for="Name" class="form-label">Name</label>
<input name="Name" id="Name" class="form-control" value="@Model.Name" required />
<span class="text-danger"></span>
</div>
<div class="mb-3">
<label asp-for="Description" class="form-label">Description</label>
<textarea asp-for="Description" class="form-control" rows="3"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
<label for="Description" class="form-label">Description</label>
<textarea name="Description" id="Description" class="form-control" rows="3">@Model.Description</textarea>
<span class="text-danger"></span>
</div>
<div class="mb-3">
<div class="form-check">
<input asp-for="IsActive" class="form-check-input" type="checkbox" />
<label asp-for="IsActive" class="form-check-label">
<input name="IsActive" id="IsActive" class="form-check-input" type="checkbox" @(Model.IsActive ? "checked" : "") />
<label for="IsActive" class="form-check-label">
Active
</label>
</div>