0

Attributes like BindRequired make an action parameter to be required, even the usual model validation attributes can be applied. How can you make all properties from a class be required to be present in the request body?

user33276346
  • 1,501
  • 1
  • 19
  • 38
  • You could try to create a [custom model binder](https://learn.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-model-binding?view=aspnetcore-5.0), then using the following code to apply ModelBinding Attribute on Action method: `public IActionResult Index([ModelBinder(BinderType = typeof(CustomModelBinder))]User u) `, check [this article](https://www.c-sharpcorner.com/article/custom-model-binding-in-asp-net-core-mvc/). – Zhi Lv Dec 31 '20 at 06:46

1 Answers1

-1

If you have access to change the class: decorate all the properties with[Required] or [BindRequired].

If you don't, you should make a DTO (Data Transfer Object) for that class and apply [Required] or [BindRequired] attributes.

Mohammad Barbast
  • 1,753
  • 3
  • 17
  • 28