c# - JSON deserialization issue with PUT request to Web API -
i trying perform update on resource using webapi
i have controller performs operation
admincontroller class
[httpput] [route("newprofile")] public httpresponsemessage update(adminaction adminaction) { if (_adminmanager.approveuser(adminaction)) { return request.createresponse(httpstatuscode.ok); } return request.createresponse(httpstatuscode.badrequest); } resource
public class adminaction : baseresource { public bool approve { get; set; } public bool delete { get; set; } public string emailid { get; set; } public string language { get; set; } [ignoredatamember] public language elanguage { get; set; } } ajax code
activate: function (e) { var email = this.model.get('email'); var adminaction = { "approve": true, "delete": false, "emailid": email, "language": $("#ddlmothertongue").val() } var url = kf.settings.apiurl() + '/admin/newprofile'; $.ajax(url, { type: "put", data: json.stringify(adminaction), success: function (data, textstatus, jqxhr) { alert('profile approved'); $("table tr td").filter(function() { return $(this).text().trim() == email; }).parent('tr').css({'border': '1px solid green', 'border-left': 'none', 'border-right': 'none','color':'green'}); }, error: function (jqxhr, textstatus, errorthrown) { if (jqxhr.status == 400) { var errorjson = jquery.parsejson(jqxhr.responsetext); if (errorjson.hasownproperty("errors")) { switch (errorjson.errors[0].errortype) { } } } }, async: true }); return false; }, fiddler
url: http://lapi.x.com/admin/newprofile
request headers
accept: application/json accept-encoding: gzip, deflate accept-language: en-us,en;q=0.8 authorization: token dd39c761-3060-498b-9393-92b12cace238 connection: keep-alive content-length: 76 content-type: application/json host: lapi.x.com origin: http://x.com referer: http://x.com/ body
{"approve":true,"delete":false,"emailid":"ttt@gnote.com","language":"hindi"} when execute put operation(fiddler , code) admin object received in put method(code behind) has types in object set default values, i.e passed values not deserialized.
any ideas have done json, server doesn't it?
because you're using datacontractjsonserializer should have added relevant attributes.
class attribute:
[datacontract] method attribute:
[datamember]
Comments
Post a Comment