I'm using ASPX 4.5.
The client sends one JSON object with dynamic fields (can be different each time)
function storeDataInSession(formData) {
var data = {};
data["formData"] = formData;
$.ajax({
url: "MY_URL/StoreFormData",
type: "post",
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'json',
success: function (data, textStatus, xhr) {
console.log(data);
console.log("success");
},
error: function (xhr, textStatus, errorThrown) {
console.log("failure");
}
});
}
On the server side I'm trying to convert that JSON to Dictionary, but I'm getting error 500.
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public String StoreFormData(dynamic formData)
{
JavaScriptSerializer jss = new JavaScriptSerializer();
Dictionary<string, string> formValues = jss.Deserialize<Dictionary<string, string>>(formData);
return "aaaaa";
}
What am I doing wrong?