Skip to main content


Showing posts with the label Csharp9

.Net 5 MVC Application Model Binding And Validation Using Record Types(C#9 Feature)

In this article, we will understand the model binding and validation that will be carried out by 'record' types c#9 feature in MVC application. Specs: C#9 .Net5 MVC Application C# 9 Record Types: The Record Types has been introduced in C# 9 feature. Using Record Types, it is effortless to create immutable reference types. Most features supported by 'Class' will be supported by the 'Record' types but in the case to make them immutable(not allow changes in the object) then it will be an ideal choice to use 'Record' types. Record Syntax Type1: public record Profile { public string FirstName { get; } public string MiddleName { get; } } Above Record, the syntax looks similar to 'class' but only defense instead of 'class' we use 'record' keyword. Always declare properties as private in records that fulfill our immutable feature. Record Syntax Type2: public record Profile(string FirstName, string MiddleName) This syntax declarat