I'm trying to do a POST
request to the server like this:
var body = {
PatientAgeFilter: {
CompareOperator: parseInt(self.patientAge()),
MoreThanVal: {
AgeSpecifier: 0,
AgeValue: parseInt(self.patientAgeLow())
},
LessThanVal: {
AgeSpecifier: 0,
AgeValue: parseInt(self.patientAgeHigh())
}
}
};
$.post(url, body, self.results, "json").done(function () {
console.log("request done!");
console.log(self.results());
});
The URL is set correctly, self.results
is a Knockout.JS observableArray()
, and the body is set as above.
Server side, this is the code handling the request:
[HttpPost]
public IQueryable<Measurement> GetMeasurements(MeasurementQuery queryOptions)
{
...
if (queryOptions != null) {
if (queryOptions.PatientAgeFilter.CompareOperator != CompareOperator.Any) {
...
}
}
}
I've set a breakpoint on if (queryOptions != null)
, and queryOptions is not null. But the content of queryOptions
stays default, even though I specify the fields in body
(f.e. the CompareOperator
should equal 3, but it stays 0 - which equals CompareOperator.Any
), so the body of the POST
request isn't parsed properly.
Can anybody help me out here as to why this happens? Much appreciated!