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
Copy file name to clipboardExpand all lines: aspnetcore/blazor/forms/validation.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1572,6 +1572,50 @@ The <xref:System.ComponentModel.DataAnnotations.CompareAttribute> doesn't work w
1572
1572
1573
1573
:::moniker range=">= aspnetcore-10.0"
1574
1574
1575
+
## Use validation models from a different assembly
1576
+
1577
+
<!-- UPDATE 10.0 - API cross-links -->
1578
+
1579
+
For model validation defined in a different assembly, such as a library or the `.Client` project of a Blazor Web App:
1580
+
1581
+
* If the library is a plain class library (it isn't based on the `Microsoft.NET.Sdk.Web` or `Microsoft.NET.Sdk.Razor` SDKs), add a package reference to the library for the [`Microsoft.Extensions.Validation` NuGet package](https://www.nuget.org/packages/Microsoft.Extensions.Validation).
1582
+
* Create a method in the library or `.Client` project that receives an <xref:Microsoft.Extensions.DependencyInjection.IServiceCollection> instance as an argument and calls `AddValidation` on it.
1583
+
* In the app, call both the method and `AddValidation`.
1584
+
1585
+
The preceding approach results in validation of the types from both assemblies.
1586
+
1587
+
In the following example, the `AddValidationForTypesInClient` method is created for the `.Client` project of a Blazor Web App for validation using types defined in the `.Client` project.
1588
+
1589
+
`ServiceCollectionExtensions.cs` (in the `.Client` project):
In the server project's `Program` file, add the namespace and call the `.Client` project's service collection extension method (`AddValidationForTypesInClient`) and `AddValidation`:
1605
+
1606
+
```csharp
1607
+
usingBlazorSample.Client.Extensions;
1608
+
1609
+
...
1610
+
1611
+
builder.Services.AddValidationForTypesInClient();
1612
+
builder.Services.AddValidation();
1613
+
```
1614
+
1615
+
:::moniker-end
1616
+
1617
+
:::moniker range=">= aspnetcore-10.0"
1618
+
1575
1619
## Nested objects and collection types
1576
1620
1577
1621
Blazor form validation includes support for validating properties of nested objects and collection items with the built-in <xref:Microsoft.AspNetCore.Components.Forms.DataAnnotationsValidator>.
Copy file name to clipboardExpand all lines: aspnetcore/release-notes/aspnetcore-10/includes/blazor.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -611,6 +611,13 @@ The <xref:Microsoft.AspNetCore.Components.Forms.DataAnnotationsValidator> compon
611
611
612
612
If one of the preceding steps produces a validation error, the remaining steps are skipped.
613
613
614
+
### Use validation models from a different assembly
615
+
616
+
You can validate forms with models defined in a different assembly, such as a library or the `.Client` project of a Blazor Web App, by creating a method in the library or `.Client` project that receives an <xref:Microsoft.Extensions.DependencyInjection.IServiceCollection> instance as an argument and calls `AddValidation` on it.
617
+
* In the app, call both the method and `AddValidation`.
618
+
619
+
For more information and an example, see <xref:blazor/forms/validation#use-validation-models-from-a-different-assembly?view=aspnetcore-10.0>.
620
+
614
621
### Custom Blazor cache and `BlazorCacheBootResources` MSBuild property removed
615
622
616
623
Now that all Blazor client-side files are fingerprinted and cached by the browser, Blazor's custom caching mechanism and the `BlazorCacheBootResources` MSBuild property have been removed from the framework. If the client-side project's project file contains the MSBuild property, remove the property, as it no longer has any effect:
0 commit comments