You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For information on how empty strings and `null` values are handled in data binding, see the [Binding `<select>` element options to C# object `null` values](#binding-select-element-options-to-c-object-null-values) section.
@@ -402,6 +457,8 @@ public class StarshipValidationController(
402
457
}
403
458
```
404
459
460
+
:::moniker-end
461
+
405
462
Confirm or update the namespace of the preceding controller (`BlazorSample.Server.Controllers`) to match the app's controllers' namespace.
406
463
407
464
When a model binding validation error occurs on the server, an [`ApiController`](xref:web-api/index) (<xref:Microsoft.AspNetCore.Mvc.ApiControllerAttribute>) normally returns a [default bad request response](xref:web-api/index#default-badrequest-response) with a <xref:Microsoft.AspNetCore.Mvc.ValidationProblemDetails>. The response contains more data than just the validation errors, as shown in the following example when all of the fields of the `Starfleet Starship Database` form aren't submitted and the form fails validation:
@@ -411,10 +468,10 @@ When a model binding validation error occurs on the server, an [`ApiController`]
411
468
"title": "One or more validation errors occurred.",
412
469
"status": 400,
413
470
"errors": {
414
-
"Id": ["The Id field is required."],
415
-
"Classification": ["The Classification field is required."],
416
-
"IsValidatedDesign": ["This form disallows unapproved ships."],
returnnewValidationResult("Validation message to user.",
1046
+
new[] { validationContext.MemberName! });
1047
+
}
1048
+
}
1049
+
```
1050
+
1051
+
:::moniker-end
1052
+
1053
+
:::moniker range="< aspnetcore-6.0"
1054
+
954
1055
```csharp
955
1056
usingSystem;
956
1057
usingSystem.ComponentModel.DataAnnotations;
@@ -968,6 +1069,8 @@ public class CustomValidator : ValidationAttribute
968
1069
}
969
1070
```
970
1071
1072
+
:::moniker-end
1073
+
971
1074
Inject services into custom validation attributes through the <xref:System.ComponentModel.DataAnnotations.ValidationContext>. The following example demonstrates a salad chef form that validates user input with dependency injection (DI).
972
1075
973
1076
The `SaladChef` class indicates the approved starship ingredient list for a Ten Forward salad.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/javascript-interoperability/call-javascript-from-dotnet.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1102,10 +1102,22 @@ The `{TIMEOUT}` placeholder is a <xref:System.TimeSpan> (for example, `TimeSpan.
1102
1102
1103
1103
Set a per-invocation timeout in component code. The specified timeout overrides the global timeout set by <xref:Microsoft.AspNetCore.Components.Server.CircuitOptions.JSInteropDefaultCallTimeout>:
0 commit comments