I have an API Controller with the following Action header:
public IHttpActionResult Post(InvoicesDTO invoices)
where InvoicesDTO is as follows:
public class InvoicesDTO
{
public int IdHeader { get; set; }
[DataType(DataType.DateTime)]
public DateTime DateSend { get; set; }
public List<InvoiceDTO> ListInvoices { get; set; }
}
and InvoiceDTO is a POCO class with some DataAnnotations validations.
The problem is that i want, when a validation error occurs, to know which InvoiceDTO of the InvoicesDTO's list is the one that has generated the error to be able to do something like this:
if (ModelState.IsValid)
{
}
else
{
_logger.LogError($"Validation Error at Invoice -
{ModelState.Values.First().WHATEVER_TO_GET_THE_ELEMENT_THAT_GENERATED_THE_ERROR");
}
thanks!