var formData = new FormData();
formData.append("ID", "1");
formData.append("Name", "Gà Haha");
console.log(formData.get("ID"));
$.ajax({
type: "POST",
url: "http://localhost:13497/myapi/student",
contentType: "json",//Request header
data:formData,
dataType: "json",//Responce header
processData: false,
success: function (data) {
$.each(data, function (key, value)
{
var jsonData = JSON.stringify(value);
var objData = $.parseJSON(jsonData);
var id = objData.ID;
var fname = objData.Name;
var lname = objData.Price;
$('<tr><td>' + id + '</td><td>' + fname + '</td><td>' + lname + '</td></tr>').appendTo('#students');
});
},
error: function (errormsg) {
alert(errormsg.responseText);
}
});
[HttpPost]
public IEnumerable<Products> GetStudents()
{
string temp=HttpContext.Current.Request.Params["ID"];
return temp;
}
但是 temp 返回null。我正在使用How can retrieve string formData js in c#,但在此处返回How to read FormData into Web api却为空,但无法正常工作。
最后:我想从FormData Client send中获取数据
答案 0 :(得分:0)
请在服务器端尝试
使用表格
HttpContext.Current.Request。表单 [“ ID”],而不是Request。 Params [“ ID”]