I am working with an ASP.NET 8 Core Web API and React Framework and I am trying to test my API using Postman for sending data to database. After running the commands dotnet run
for my backend app and npm start
for the React frontend, I get this error:
This is my model file:
namespace PhotoAlbums.Models
{
public class Album
{
public int Id { get; set; }
public int UserId { get; set; }
public string? Title { get; set; }
}
}
And my controller file:
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PhotoAlbums.Data;
using PhotoAlbums.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace PhotoAlbums.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AlbumsController : ControllerBase
{
private readonly ApplicationDbContext _context;
public AlbumsController(ApplicationDbContext context)
{
_context = context;
}
[HttpPost]
public async Task<ActionResult<Album>> PostAlbum([FromBody] Album album)
{
_context.Albums.Add(album);
await _context.SaveChangesAsync();
return CreatedAtAction(nameof(PostAlbum), new { id = album.Id }, album);
}
private bool AlbumExists(int id)
{
return _context.Albums.Any(e => e.Id == id);
}
}
}
Also in my error is including the album field is required and I don’t have column with name album
in my table. Any help?