Remote validation checks a field asynchronously by sending its value to a server endpoint, then displays the returned result in the client. It sits between ordinary client-side checks and full server-side model validation: JavaScript controls the interaction, while the application performs the check. section 29.7
Use remote validation when a value depends on server-held data:
- Check whether a username is already taken before the user submits the form. section 29.7
- Verify that CategoryId and SupplierId identify existing database records. section 29.7
- Keep the request focused on one validation value instead of submitting and processing the entire model. section 29.7
Database-backed key validation
Expose GET endpoints such as /api/Validation/categorykey and /api/Validation/supplierkey. Each action accepts a parameter matching the field being validated, parses the submitted value, queries the corresponding data set, and returns true only when the record exists. Apply the Remote attribute to the model property so client-side validation calls the endpoint. section 29.7
Razor Pages alter the query-string shape: controller requests can use CategoryId, while page requests can use Product.CategoryId. Accept both forms through model binding when one validation action must serve both request styles. section 29.7.1
The trade-off is responsiveness versus an extra server request. Remote checks avoid a submit-and-render cycle but remain slower than purely client-side validation and still depend on the application server. section 29.7
