0

Let's say I have 2 textboxes in a user registration form

  • Email
  • Username

User is required to fill up 1 of them but not both.

How can this be done using ASP.NET Core model validation?

Adding [Required] attribute on both Email and Username properties did not achieve the objective

MaxMoore
  • 5
  • 2
  • Please provide enough code so others can better understand or reproduce the problem. – KargWare Mar 04 '23 at 07:44
  • @MikeBrind I saw this solution (adding AddModelError) in your book too. Does this mean I should not use the [Required] attribute for Email and Username properties? – MaxMoore Mar 04 '23 at 11:31
  • Correct. the Required attribute is for a property where you always need a value, not only in some circumstances. – Mike Brind Mar 04 '23 at 17:04

0 Answers0