0

I think i might be too dumb, but I've already ready this answers:

ASP.NET Core API POST parameter is always null https://github.com/dotnet/aspnetcore/issues/2202

But none of above worked for me.

This is my model:

[DataContract]
    public class Video
    {
        public Video()
        {

        }

        public Video(string titulo, string descricao, string url)
        {
            this.Titulo = titulo;
            this.Descricao = descricao;
            this.Url = url;
        }

        public int Id { get; private set; }
        public string Titulo { get; private set; }
        public string Descricao { get; private set; }
        public string Url { get; private set; }

    }

This is my controller:

[ApiController]
    [Route("[controller]")]
    public class VideosController : ControllerBase
    {
        private readonly IVideoRepository _videoReposiroty;

        private readonly ILogger<VideosController> _logger;

        public VideosController(ILogger<VideosController> logger,
            IVideoRepository videoReposiroty)
        {
            _logger = logger;
            _videoReposiroty = videoReposiroty;
        }

        // GET: Videos
        public IEnumerable<Video> Get()
        {

            return _videoReposiroty.GetVideos();
        }

        // GET: Videos/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            var video = _videoReposiroty.GetVideo(id);
            if (video == null)
            {
                return "{message: \"Não encontrado\"}";
            }
            var jsonString = JsonSerializer.Serialize(video);
            return jsonString;
        }

        // POST: Videos
        [HttpPost]
        public Video Post(Video video)
        {
            return _videoReposiroty.CreateVideo(video);
        }
    }

And this is my request:

enter image description here

But all the never que the right body. I don't know what to do anymore

3
  • 2
    private set; Remove private. Also read andrewlock.net/model-binding-json-posts-in-asp-net-core . Commented Jul 26, 2021 at 0:09
  • I fell really really dumb right now. Hahaha But this solved! Thank you!!! Commented Jul 26, 2021 at 0:11
  • All good. Have a great day. Commented Jul 26, 2021 at 0:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.