0

In my ASP.NET Core application, I have a BassModel class.

In it, I have a field that is marked as required:

[Required(ErrorMessage = "Required field")]
public string InputText { get; set; }

So all other classes were inherited from this class. Now there is a second class and in that class, I am not passing this value to the controller from the view.

Simply I want to make this required attribute disabled.

I know most people suggest making that parent attribute allow null. But I don't want to do it either. Is there a better approach?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Prageeth Liyanage
  • 1,612
  • 2
  • 19
  • 41
  • In my opinion, I don't think you can achieve it instead of setting nullable in father class. – Xinran Shen Dec 26 '22 at 08:50
  • Make the `InputText` nullable in `BassMode` but make it `abstract`. Then update all your derived classes to implement `InputText` and make it required where necessary. – Tim Jarosz Dec 28 '22 at 22:31

0 Answers0