Hi @Yusuf ,
C# 8.0 introduces nullable reference types, which complement reference types the same way nullable value types complement value types. You declare a variable to be a nullable reference type by appending a ? to the type. For example, string? represents a nullable string. You can use these new types to more clearly express your design intent: some variables must always have a value, others may be missing a value.
Prior to .NET 6, new projects do not include the Nullable element. Beginning with .NET 6, new projects include the <Nullable>enable</Nullable>
element in the project file. Like this:
public string title { get; set; }
public string text { get; set; }
public string image { get; set; }
public bool displayInCarousel { get; set; }
So, in your code, if you enable the Nullable in the project file and use the above code, it means these properties are non-nullable property. So, when submit the form, it will show the property is required validation error.
To solve this issue, you can try to use the following solutions:
- Make the properties nullable, add the
?
like this:public string? title { get; set; } public string? text { get; set; } public string? image { get; set; }
- Disable the Nullable feature: open the project file and change the
enable
todisable
, like this:
In this scenario, there is no need to add '?' for the property. If you want to make the property required, you need to add the [Required]
attribute. The result like this:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion