Form data is posted using jquery:
$.ajax('API/Validate/Customer?column=1&rowid=2&vmnr=3&isik=4',
{
data: JSON.stringify({
headerData: $("#_form").serializeArray()
}),
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST"
});
It is received by ASP.NET MVC4 Web API controller Validate:
public class ValidateController : ApiController
{
public class Body
{
public Dictionary<string, string> headerData { get; set; }
public Dictionary<string, string> rowData { get; set; }
}
public HttpResponseMessage Validate(
string id,
string column,
string rowid,
int? vmnr,
string isik,
[FromBody] Body body,
string dok = null,
string culture = null,
uint? company = null
)
{ ...
body.headerData value is null in controller.
According to answer in How to receive dynamic data in Web API controller Post method
body.headerData must have form keys. However, it is empty.
How to get headerData as key, value pairs in controller ?
Chorme developer tools show that proper json is posted in body:
{"headerData":[{"name":"Kalktoode","value":"kllöklö"},
{"name":"Kaal","value":""}
]}
I tried to remove
public Dictionary<string, string> rowData { get; set; }
from class but problem persists.