Fix: Categories Edit IsActive checkbox now works both ways
Fixed two issues preventing IsActive toggle: 1. Removed hidden field that was sending "false" even when checkbox checked 2. Updated CategoryService to always update IsActive, treating null as false Checkbox behavior: - Checked → sends "true" → IsActive = true - Unchecked → sends nothing (null) → IsActive = false (via ?? operator) This allows both setting inactive→active and active→inactive. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
261c3e0580
commit
ec955e49d9
@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input type="hidden" name="IsActive" value="false" />
|
|
||||||
<input name="IsActive" id="IsActive" class="form-check-input" type="checkbox" value="true" @(Model.IsActive == true ? "checked" : "") />
|
<input name="IsActive" id="IsActive" class="form-check-input" type="checkbox" value="true" @(Model.IsActive == true ? "checked" : "") />
|
||||||
<label for="IsActive" class="form-check-label">
|
<label for="IsActive" class="form-check-label">
|
||||||
Active
|
Active
|
||||||
|
|||||||
@ -89,10 +89,8 @@ public class CategoryService : ICategoryService
|
|||||||
category.Description = updateCategoryDto.Description;
|
category.Description = updateCategoryDto.Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateCategoryDto.IsActive.HasValue)
|
// Always update IsActive - treat null (unchecked) as false
|
||||||
{
|
category.IsActive = updateCategoryDto.IsActive ?? false;
|
||||||
category.IsActive = updateCategoryDto.IsActive.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user