我已经实现了这样的控制器:
[HttpPost]
[ActionName("DefaultAction")]
public HttpResponseMessage Post(Person obj){
}
人是这个类:
public class Person
{
public String Name { get; set; }
public byte[] ImageStream { get; set; }
}
在客户端,我打这个电话来发布新的人:
var person={
"Name":"Test",
"ImageStream":"AQID"
}
$.ajax({
type: "POST",
url: "/person",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(person),
success: function (result) {
console.log(result); //log to the console to see whether it worked
},
error: function (error) {
alert("There was an error posting the data to the server: " + error.responseText);
}
});
问题是我收到了 ImageStream 设置为 null 的 Person obj。
为了测试我使用的 ImageStream 字符串是否正确,我尝试了这个:
Person p=new Person();
p.Name="Test";
p.ImageStream=new byte[]{1,2,3};
String json=JsonConvert.SerializeObject(p);