.NET code examples

Data Annotation custom validator in ASP.NET Core

Data Annotation custom validator in ASP.NET Core

Download a Data Annotation custom validator written in C# that can be used in .NET with MVC and Web API for model validation.
A FromBody and FromQuery sample in ASP.NET Core Web API

A FromBody and FromQuery sample in ASP.NET Core Web API

An ASP.NET Core example of using the FromBody and FromQuery attribute. Handy if your request is null, or getting a 415 error.
Download a Blazor WebAssembly button onclick event example

Download a Blazor WebAssembly button onclick event example

Use a Blazor Wasm parameter to pass the onclick event to another Razor compoment and use it async. Download the code example.
Dynamic queries using LINQ expressions

Dynamic queries using LINQ expressions

Writing dynamic queries for Entity Framework. A sample .NET 5 MVC application, showing examples of LINQ expressions.
.NET 6 new features using ASP.NET Core

.NET 6 new features using ASP.NET Core

Download an ASP.NET Core 6 application that demonstrates new .NET 6 features, using C# 10 and Visual Studio 2022.
EF Core 6 new features examples for .NET 6

EF Core 6 new features examples for .NET 6

Download a EF Core 6 sample for new features. See what's new as part of the .NET 6 update, including migration bundles.
.NET 6 Minimal APIs sample using ASP.NET Core

.NET 6 Minimal APIs sample using ASP.NET Core

Download a ASP.NET Core Web API using .NET 6 Minimal APIs. No need for controllers, reducing boilerplate code.
Try out C# 10 new features using Visual Studio 2022

Try out C# 10 new features using Visual Studio 2022

An ASP.NET Core 6 Web API that showcases five new features of C Sharp 10. Run the application using Visual Studio 2022.
Dependency injection in ASP.NET Core

Dependency injection in ASP.NET Core

Download the code example for using dependency injection in ASP.NET Core, which uses the singleton, scoped and transient service lifetimes.
Read appsettings.json config in ASP.NET Core

Read appsettings.json config in ASP.NET Core

Download the source code and read the appsettings.json file in an ASP.NET Core MVC application. Bind using the options pattern.