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

86
Visualizações
dotnet5 MVC Giving POST Data to API does not work

I have done an udemy Tutorial for MVC in dotnet5 and try to implement my own project on this base. I have built a form with a body like this:

<form id="genreForm" autocomplete="off" novalidate="novalidate">
            <div class="">
                Genre &nbsp;
            </div>
            <div class="container closed">lorem Ipsum</div>
            <div>
                <input type="text" id="newGenreName" />
                <input type="text" id="newGenreDescription" />
                <button type="button" id="btnSubmit" class="btn btn-success" onclick="onGenreAddForm();">Genre hinzufügen</button>
            </div>
        </form>

And an ajax request like this:

function onGenreAddForm() {
    var requestData = {
        GenreName: $("#newGenreName").val(),
        GenreDescription: $("#newGenreDescription").val()
    };
    $.ajax({
        url: routeURL + '/api/Event/AddUpdateGenre',
        type: 'POST',
        data: JSON.stringify(requestData),
        contentType: 'application/json',
        success: function (response) {
            
        },
        error: function (xhr) {
            $.notify("Error", "error");
        }
    });
}

which routes to an API Controler looking like this:

[HttpPost]
    [Route("AddUpdateGenre")]
    public IActionResult AddUpdateGenre(ManagementVM data)
    {
        doSthWithData(data);
    }

while the ManagementVM has members like

public string GenreName { get; set; }
public string GenreDescription { get; set; }

Now, when i fire the button, the js fills the requestData with the right values an the right keys, but when i inspect ManagementVM data in the APIController, it is filled with nulls. Can anyone tell me, where is my fault? I followed the same steps described in the tutorial.

Thanks a lot!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

solved by adding [FromBody] to the Param in API:

    public IActionResult AddUpdateGenre([FromBody] ManagementVM data)
about 4 years ago · Juan Pablo Isaza Relatório
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