Post multiple values to WebAPi using jQuery

No comments


                    url: "/Api/AppointmentApi/MatchAppointment",
                    type: "POST",
                    dataType: "json",
                    data: JSON.stringify({ appointmentId: appointment.ID, contractId: contract.ID }),
                    contentType: "application/json; charset=utf-8",
                    context: this,
                    success: function (results) {
                    error: function (jqXHR, textStatus, errorThrown) {
                        self.Info(textStatus + ": " + errorThrown);

To post multiple values to a WebApi method you need to convert it first to a json string using JSON.stringify.

WebApi will correctly do the reverse transformation and rebuild the object:


        public dynamic MatchAppointment(dynamic data)
            int appointmentId = data.appointmentId;
            int contractId = data.contractId;

            var rslt=doSomething...
            return rslt;

No comments :

Post a Comment