Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

82
Vistas
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 Respuestas
Responde la pregunta

0

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

    public IActionResult AddUpdateGenre([FromBody] ManagementVM data)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda