liveBook · Manning

Remote validation

As explained in Pro ASP.NET Core 7, Tenth Edition

Remote validation is a validation technique that sends a value to a server endpoint for asynchronous checking and returns the validation result to the client.

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

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Builds controller endpoints, matching parameters, Remote attributes, database checks, and Razor Pages query compatibility; stops short of deeper client-script internals.
Examples
Demonstrates username availability plus CategoryId and SupplierId existence checks through ValidationController endpoints.
What it assumes
Assumes familiarity with model validation and client/server request processing, while demonstrating the required model-binding parameter shapes.
What you can do after
Apply it via ASP.NET Core validation endpoints and the Remote attribute, including requests originating from Razor Pages.
How it connects
Connects client-side validation, server-side validation, model binding, database lookup, controllers, and Razor Pages.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.