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

93
Vistas
How to building a fetch call to pass value to a method that expects an Object?

I currently not sure how to use a fetch post call to pass an object to a method expecting that object. I created a payload and passed it but does not seem to work. I have set a breakpoint in the code behind but it is never hit. Not sure why the fetch call is not working. Any suggestions on way the endpoint is not being reached?

This is my method in C#.

    [HttpPost]
    [Route("ResetPassword")]
    private void ResetPassword(Player player){

   {

Javascript:

const continueBtn = document.getElementById("continueBtn");
continueBtn.onclick = () => {
const email = document.getElementById("lblEmail").innerHTML;
sendResetEmail(email);
}

async function sendResetEmail(email) {
const payload = {
    email: email
}

const data = new FormData();
data.append("json", JSON.stringify(payload));

let sendResetEmail = await fetch(`/ResetPassword`,
    {
        method: 'POST',
        body: data
    });
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

if you don't want to provide the name of the parameter in your client, you need to give the [FromBody] attribute in your API:

[HttpPost]
[Route("ResetPassword")]
private void ResetPassword([FromBody] Player player){
}

Then, on the client, there are multiple ways, but the most common/modern is to use JSON encoding:

const payload = {
    email: email
}

const data = JSON.stringify(payload);

let sendResetEmail = await fetch(`/ResetPassword`,
    {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: data
    });
}
about 4 years ago · Juan Pablo Isaza 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