Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!