Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
how can i change the value of FormData() to receive the value of the textbox?

I'm fetching data from an API and putting it in a table in react so far so good, but when I try to edit the data from a row in the table. This gives me the error "PUT 400 (Bad Request)". How should I change the FormData() to receive the value from "<Form.Control/>" and later receive it from the backend?

---Editar2.js---

handlerSubmit = async (event) => {

        event.preventDefault();
        let formData = new FormData();
        formData.set("", event.target.legenda.value);
        
        let resposta = await fetch("api/FotografiasAPI/" + this.props.idLinha, {
            method: "PUT",
            headers:{'Accept':'application/json','Content-Type':'application/json'},
            body: formData
        });
        if (!resposta.ok) {
        console.error("error:" + resposta.status);
        }
        return await resposta.json();
}
    render(){
        return(
        <Modal
        {...this.props}>
                <Form onSubmit={this.handlerSubmit}>
                    <Form.Group controlId="legenda">
                        <Form.Label>legenda</Form.Label>
                        <Form.Control defaultValue = {this.props.legenda} type="text"name="legenda" required  placeholder="legenda"/>
                    </Form.Group>
                    <Form.Group>
                        <Button variant="primary" type="submit">
                            Editar Restaurante
                        </Button>
                    </Form.Group>
                </Form>    
        </Modal>  
    );}}

---Backend---

[HttpPut("{id}")]
public async Task<IActionResult> PutFotografias(int id, [FromForm] Fotografias fotografias)
{
    if (id != fotografias.ID)
    {return BadRequest();}

    _context.Entry(fotografias).State = EntityState.Modified;

    try
    {await _context.SaveChangesAsync();}

    catch (DbUpdateConcurrencyException)
    {
        if (!FotografiasExists(id))
        {return NotFound();}

        else
        {throw;}}

    return NoContent();
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda