JSON.Stringify data including boolean values

Posted by ancdev on Stack Overflow See other posts from Stack Overflow or by ancdev
Published on 2012-11-01T10:52:02Z Indexed on 2012/11/01 11:00 UTC
Read the original article Hit count: 246

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about JavaScript