title: How to validate an object of type DTO?
body: <p>hello community I have a problem before I have already used EditForm in blazor wasm, and work with <strong>DataAnnotationsValidator</strong> to validate my fields, and it works perfectly alone and when I pass an object to the Model for example <strong>Model=&quot;@Persona&quot;</strong>,now the problem arises when I pass a DTO to the model like this <strong>Model=&quot;@PersonaEmpleadoDTO&quot;</strong>,, in my dto class I have two person and employee objects and in my form I get their information like this:</p>
  <blockquote>
  <p>@bind-Value=&quot;@PersonaEmpleadoDTO.Persona.Nombre&quot;</p>
  </blockquote>
  <p>but when I want to validate the name field and any other the error message does not appear on the screen, I validate it this way:</p>
  <pre><code>&lt;ValidationMessage For=&quot;@(() =&gt; PersonaEmpleadoDTO.Persona.Nombre)&quot; /&gt;
  </code></pre>
  <p>this is my class Persona:</p>
  <pre><code>public class Persona
      {
          [Key]
          public int PersonaId { get; set; }
  
          [Required(ErrorMessage = &quot;El campo {0} es requerido&quot;)]
          public string Nombre { get; set; }
  
          [Required(ErrorMessage = &quot;El campo {0} es requerido&quot;)]
          public string Ap_Paterno { get; set; }
  
          [Required(ErrorMessage = &quot;El campo {0} es requerido&quot;)]
          public string Ap_Materno { get; set; }       
          public string Email { get; set; }
          public string Telefono { get; set; }
          public string Celular { get; set; }       
      }
  </code></pre>
  <p>this is my class Empleado:</p>
  <pre><code> public class Empleado
      {
          [Key]
          public int EmpleadoId { get; set; }      
          public int Num_Empleado { get; set; }    
          public string Correo_Empleado { get; set; }
          public string Telefono_Empleado { get; set; }
         
      } 
  </code></pre>
  <p>this is my DTO class:</p>
  <pre><code>public class PersonaEmpleadoDTO
      {
          public Persona Persona { get; set; } = new Persona();
          public Empleado Empleado { get; set; } = new Empleado();
      }
  </code></pre>
  <p>this is my formulario:</p>
  <pre><code>&lt;EditForm Model=&quot;@PersonaEmpleadoDTO&quot; OnValidSubmit=&quot;OnValidSubmit&quot;&gt;
      &lt;DataAnnotationsValidator /&gt;
      &lt;div class=&quot;form-row&quot;&gt;
          &lt;div class=&quot;col-sm-3&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;InputLabel for=&quot;nombre&quot;&gt;Nombre&lt;/InputLabel&gt;
                  &lt;InputText class=&quot;form-control form-control-sm&quot; id=&quot;nombre&quot; placeholder=&quot;Nombre&quot; @bind-Value=&quot;@PersonaEmpleadoDTO.Persona.Nombre&quot; /&gt;
                  &lt;ValidationMessage For=&quot;@(() =&gt; PersonaEmpleadoDTO.Persona.Nombre)&quot; /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-sm-3&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;InputLabel for=&quot;ap-paterno&quot;&gt;Apellido Paterno&lt;/InputLabel&gt;
                  &lt;InputText class=&quot;form-control form-control-sm&quot; id=&quot;ap-paterno&quot; placeholder=&quot;Apellido Paterno&quot; @bind-Value=&quot;@PersonaEmpleadoDTO.Persona.Ap_Paterno&quot; /&gt;
                  &lt;ValidationMessage For=&quot;@(() =&gt; PersonaEmpleadoDTO.Persona.Ap_Paterno)&quot; /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-sm-3&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;InputLabel for=&quot;ap-materno&quot;&gt;Apellido Materno&lt;/InputLabel&gt;
                  &lt;InputText class=&quot;form-control form-control-sm&quot; id=&quot;ap-materno&quot; placeholder=&quot;Apellido Materno&quot; @bind-Value=&quot;@PersonaEmpleadoDTO.Persona.Ap_Materno&quot; /&gt;
                  &lt;ValidationMessage For=&quot;@(() =&gt; PersonaEmpleadoDTO.Persona.Ap_Materno)&quot; /&gt;
              &lt;/div&gt;
          &lt;/div&gt;            
          &lt;div class=&quot;col-sm-3&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;InputLabel for=&quot;email&quot;&gt;Email&lt;/InputLabel&gt;
                  &lt;InputText id=&quot;email&quot; type=&quot;text&quot; placeholder=&quot;Email&quot; class=&quot;form-control form-control-sm&quot; @bind-Value=&quot;@PersonaEmpleadoDTO.Persona.Email&quot; /&gt;
                  &lt;ValidationMessage For=&quot;@(() =&gt; PersonaEmpleadoDTO.Persona.Email)&quot; /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-sm-3&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;InputLabel for=&quot;telefono&quot;&gt;Teléfono&lt;/InputLabel&gt;
                  &lt;InputText id=&quot;telefono&quot; placeholder=&quot;Teléfono&quot; type=&quot;text&quot; class=&quot;form-control form-control-sm&quot; @bind-Value=&quot;@PersonaEmpleadoDTO.Persona.Telefono&quot; /&gt;
                  &lt;ValidationMessage For=&quot;@(() =&gt; PersonaEmpleadoDTO.Persona.Telefono)&quot; /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;col-sm-3&quot;&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;InputLabel for=&quot;celular&quot;&gt;Celular&lt;/InputLabel&gt;
                  &lt;InputText id=&quot;celular&quot; placeholder=&quot;Celular&quot; type=&quot;text&quot; class=&quot;form-control form-control-sm&quot; @bind-Value=&quot;@PersonaEmpleadoDTO.Persona.Celular&quot; /&gt;
                  &lt;ValidationMessage For=&quot;@(() =&gt; PersonaEmpleadoDTO.Persona.Celular)&quot; /&gt;
              &lt;/div&gt;
          &lt;/div&gt;       
      &lt;/div&gt;
     &lt;button class=&quot;btn btn-primary&quot; type=&quot;submit&quot;&gt;Guardar&lt;/button&gt;
  &lt;/EditForm&gt;
  </code></pre>
  <p>this is my controller:</p>
  <pre><code>[HttpPost]
          public async Task&lt;ActionResult&lt;int&gt;&gt; Post(PersonaEmpleadoDTO personaempleado)
          {
              context.Add(personaempleado.Persona);
             
              personaempleado.Empleado.Persona = personaempleado.Persona;       
  
              context.Add(personaempleado.Empleado);
  
              await context.SaveChangesAsync();
              return personaempleado.Persona.PersonaId;
          }
  </code></pre>
  <p>because it does not validate the name with:
  <strong>&lt;ValidationMessage For=&quot;@(() =&gt; PersonEmpleadoDTO.Persona.Name)&quot;</strong> /&gt; ??</p>