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

316
Views
estado: 400 título: "Ocurrieron uno o más errores de validación".

Actualmente recibo el código de error 400 y no entiendo muy bien qué es lo que está mal. He intentado buscar respuestas en línea, pero ninguno de los resultados está siendo de mucha ayuda. Cualquier ayuda/percepción sería muy apreciada. Gracias.

El valor JSON no se pudo convertir a TheMoonshineCafe.Models.Event. Ruta: $ | Número de línea: 0 | BytePositionInLine: 1.

¿Parece que la carga útil no se está convirtiendo correctamente al tipo de evento?

Edite la función de evento desde mi servicio de datos:

 editEvent(id: Number, event: EventWithID[]){ var callResult : any; console.log(id); console.log(event); this.http.put(this.baseUrl + 'api/Events/' + id, event).subscribe(result => { callResult = result; console.log(result); }) }

Poner evento de mi API:

 [HttpPut("{id}")] public async Task<ActionResult<Event>> PutEvent(int id, Event @event) { if (id != @event.id) { return BadRequest(); } _context.Entry(@event).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }

carga útil:

 export class EventWithID { id: number; eventStart: Date; eventEnd: Date; refundCutOffDate: Date; bandName: String; bandImagePath: String; bandLink: String; maxNumberOfSeats: number; currentNumberOfSeats: number; ticketPrice: number; description: String; }

Modelos.Evento:

 public class Event { public int id {get; set; } public DateTime eventStart { get; set; } public DateTime eventEnd { get; set; } public DateTime refundCutOffDate { get; set; } public string bandName { get; set; } public string bandImagePath { get; set; } public string bandLink { get; set; } public int maxNumberOfSeats { get; set; } public int currentNumberOfSeats { get; set; } public double ticketPrice { get; set; } public string description { get; set; } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

arreglar la acción

 public async Task<ActionResult<Event>> PutEvent(Event model) { if(model.Id==0) return BadRequest("Wrong Id"); var existedEvent= await _context.Set<Event>().FirstOrDefaultAsync(i=> i.Id==model.Id); if (existedEvent==null ) return BadRequest("Record not found"); _context.Entry(existedEvent).CurrentValues.SetValues(model); try { await _context.SaveChangesAsync(); } ......

y javascript

 this.http.put(this.baseUrl + 'api/Events', event).subscribe(result => { ....

y en lugar de poner, recomiendo encarecidamente usar post.

about 4 years ago · Juan Pablo Isaza Report
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!