JSON.Stringify data including boolean values
- by ancdev
What I'm trying to do is to pass JSON object to a WebAPI ajax call and mapped to a strongly typed object on the server side. String values are being posted perfectly however when it comes to boolean values, they are not being passed at all. Below is my code:
var gsGasolineField = $('.gsGasoline').val();
blData = { Gasoline: gsGasolineField };
var json = JSON.stringify(blData);
$.ajax({
type: "POST",
url: url,
data: json,
contentType: "application/json",
dataType: "json",
statusCode: {
201 /*Created"*/: function (data) {
$("#BusinessLayerDialog").dialog("close");
ClearForm("#BusinessLayerForm");
},
400: /*Bad request - validation error*/ function (data) {
$("#BusinessLayerForm").validate().form();
},
500: function (data) {
alert('err');
}
},
beforeSend: setHeader
});
Gasoline property is of type boolean on the server side.