Reputation: 20709
MyPage.cshtml.cs
[ValidateNever] // <-----
public string ProductName { get; set; }
MyPage.cshtml
<input [email protected] />
That renders:
<input type="text" data-val="true" data-val-required="The ProductName field is required." id="ProductName" name="ProductName" value="">
I expected [ValidateNever]
would suppress validation attributes, but they are emitted anyway.
How can I suppress them?
Upvotes: 2
Views: 330
Reputation: 21916
From .NET 6+ the non-nullable property must be required, otherwise the ModelState will be invalid.
The easist way, change your code like below:
[ValidateNever] // <-----
public string? ProductName { get; set; }
Upvotes: 3