出于某种原因,我无法让 ServiceStack 序列化发布的 (serializeArray) 表单数据。发布的json是:
{"somestuff":"someData","formInput":[{"name":"1","value":"2"},...]}
我用来发布表单的 jQuery:
var formData = $("form").serializeArray();
var data = {
someOtherFields: some data,
formInput: formData
};
$.ajax({
type: "post",
url: "/api/location",
data: data,
dataType: "json",
success: function(response) {
if (response.status == "success") {
scope.showForm = false;
scope.status = "successfully added message";
} else {
scope.status = response.message;
}
}
});
这是发布到带有 DTO 的 ServiceStack 服务:
public class ServiceRequest
{
other atributes;
public List<ArraySerializeResult> FormInput { get; set; }
}
public class ArraySerializeResult
{
public string Name { get; set; }
public string Value { get; set; }
}
其他属性被序列化很好,但 formInput 被序列化为具有正确数量元素的列表,但所有名称和值对都为空。