-
Notifications
You must be signed in to change notification settings - Fork 30
Closed
Description
I encountered a strange behavior for the Remote validator.
After the remote validator fire, regardless of the result, the form is posted even if the form is invalid.
It seem the preventDefault and the stopPropagation of the submit event is skipped, but I cannot understand how to fix it.
@page
@model IndexModel
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<form method="post">
<label asp-for="Id"></label>
<input asp-for="Id" />
<span asp-validation-for="Id"></span>
<label asp-for="Control"></label>
<input asp-for="Control" />
<span asp-validation-for="Control"></span>
<button type="submit">Save</button>
</form>
<script src="aspnet-validation.js"></script>
<script>
const service = new aspnetValidation.ValidationService();
service.bootstrap();
</script>
</body>
</html>public class IndexModel : PageModel
{
[BindProperty]
[Required]
[Remote("CheckRemote", "Validations", HttpMethod = "Post")]
public string Id { get; set; }
[BindProperty]
[Required]
public string Control { get; set; }
public IActionResult OnPost()
{
if (!ModelState.IsValid)
{
return BadRequest();
}
return Content("OK");
}
}
[ApiController]
[Route("api/[controller]")]
public class ValidationsController : ControllerBase
{
[HttpPost]
[Route("check-remote")]
public IActionResult CheckRemote()
{
bool isValid = false;
return Ok(isValid);
}
}Metadata
Metadata
Assignees
Labels
No labels