Posted values to MVC6 controller are null

Viewed 775

I am porting my web application from MVC5 to MVC6. This function used to work fine in MVC5 but not in MVC6.

I am posting data, via AngularJS, to this WebAPI method but the search parameter is always null. Ive tried decorating it with [FromBody] and [FromHeader] but neither seem to work. The controller gets hit, the value is just null, what is wrong?

[HttpPost("AdvancedSearch")]
public List<MatchResult> AdvancedSearch(string searchParameter)
{
    var searchResults = service.GetResults(searchParameter);

    return searchResults;
}

My AngularJS call looks like this

myAPI.advancedSearch = function (searchParameter) {
    var url = '/api/advancedsearch/';

    // Request data
    return $http({
        method: 'POST',
        data: { searchParameter: searchParameter },
        url: url
    });
}

I verified that the data is sent, in Chrome webtools the "Request Payload" is correct

{searchParameter: "n1"}
3 Answers
Related