ASP.NET Core MVC Interview Question #39

What is the difference between server-side and client-side validation?

Controllers, Actions, Model Binding & Action Results Junior Beginner

Quick Interview Answer

Server-side validation executes on the server and must be treated as the authoritative validation layer. Client-side validation runs in the browser and improves usability by displaying errors without a full request when supported.

Detailed Explanation

Server-side validation executes on the server and must be treated as the authoritative validation layer. Client-side validation runs in the browser and improves usability by displaying errors without a full request when supported.

Client-side validation is not a security boundary because a client can disable or bypass JavaScript and submit requests directly. Important rules must always be enforced on the server.

Code Example

<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>

@section Scripts {
    <partial name="_ValidationScriptsPartial" />
}