Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

507
Vistas
How to use [FromBody] and [FromQuery] attribute at the same time?

In the post request,I need to get the parameters from the query string at the same time.This is my code,but can't work


 [HttpPost("test")]
 public string Test(TestRequest request)
 {
      //TODO  ...
 }


    public class TestRequest
    {
        [FromHeader(Name = "id")]
        public string Id { get; set; }

        [FromQuery(Name = "traceId")]
        public string Trace { get; set; }

        public string Name { get; set; }

        [MaxLength(4)]
        public string Mark { get; set; }

        [Range(18, 35)]
        public int Age { get; set; }
    }

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You have to put the different parameters in the method signatur, so it would be something like

[HttpPost("test/{traceId}")] // Note the query parameter 
public string Test(
    [FromHeader(Name = "id")]string id,
    [FromQuery(Name = "traceId")]string trace,
    [FromBody]Request request
    )
{
    // TODO...
}

public class Request
{
    public string Name { get; set; }
    public string Mark { get; set; }
    public int Age { get; set; }
}

bit depending on how your actual request looks like. This would read a Request-Object form the body, the id from the header and the traceId from the query.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda