A set of technologies in the .NET Framework for building web applications and XML web services.
Hi @Pablo The Tiger ,
Thanks for reaching out.
The overall structure of your page is fine. It seems like the issue is in how the POST handler is being wired up and how the product ID is being passed back to the server.
First, regarding the handler name: in Razor Pages, when you define a method like:
public IActionResult OnPostDeleteConfirm(int id)
the correct value for the form attribute is:
asp-page-handler="DeleteConfirm"
You should not include the OnPost prefix in the asp-page-handler. Razor automatically maps OnPostDeleteConfirm to DeleteConfirm. If the handler name doesn’t match correctly, the method will never be hit, which explains why your breakpoint is not triggered.
Next, the hidden input field needs to match the method parameter name exactly. Your handler expects an int id, so your hidden field must be:
<input type="hidden" name="id" id="idInput" />
If the name is different (for example paramName), model binding won’t map the value to the id parameter.
Another important point is the use of id="openModalBtn" inside your foreach loop. Since this button is rendered once per row, you are generating multiple elements with the same ID. IDs must be unique, and currently your JavaScript will only attach to the first button found. Replacing the ID with a class and attaching the event handler using querySelectorAll ensures the correct product ID is captured before submitting the form.
Finally, regarding Model.productos becoming null: this usually happens when the handler is not executed and the page re-renders without going through a proper redirect. Once the handler runs and you return:
return RedirectToPage("Index");
a fresh GET request will populate productos again via OnGet().
If the problem persists after these changes, you may need to review how the scripts are loaded or whether the form submission is being blocked by another client-side error.
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.