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

83
Views
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 answers
Answer question

0

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

    public IActionResult AddUpdateGenre([FromBody] ManagementVM data)
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!