我正在尝试将列表发布到我的 MVC 控制器..
控制器: // POST api/UserFollows
public HttpResponseMessage PostUserFollows(List<FollowItem> followItemList)
{
//I'M GETTING NULL IN followItemList
if(followItemList==null)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
输出:
STATUS 400 Bad Request <-- Means I got null in followItemList
TIME 4025 ms
Cache-Control →no-cache
Connection →Close
Content-Length →0
Date →Tue, 29 Jan 2013 09:38:31 GMT
Expires →-1
Pragma →no-cache
Server →ASP.NET Development Server/10.0.0.0
X-AspNet-Version →4.0.30319
FollowItem
班级_
namespace Helpers.SubClasses
{
public class FollowItem
{
public bool action;
public long FollowsUserId;
}
}
我尝试了很多请求,但没有一个有效..我总是得到空!
发布方法:
function postFollowList() {
$.ajax( {
url: Request_Url + "api/UserFollows",
type: 'post',
data: {
{action: true, FollowsUserId: 123456777},
{action: true, FollowsUserId: 123456888}
},
dataType: 'json',
success: function( data )
{
$('#newmovie').html("OK");
},
error: function (jqXHR, textStatus, err)
{
$('#newmovie').html('Error: ' + err);
}
});
请求: //作为 JSON - 我正在使用POSTMAN
1.
[
{"action":"true","FollowsUserId":"123456777"}
]
2.
[
{action: true, FollowsUserId: 123456777},
{action: true, FollowsUserId: 123456888}
]
3.
{[
{action: true, FollowsUserId: 123456777},
{action: true, FollowsUserId: 123456888}
]}
4.
{followItemList:[
{action: true, FollowsUserId: 123456777},
{action: true, FollowsUserId: 123456888}
]}
空值示例:
我尝试了更多..有人可以帮我吗?谢谢!!!
编辑:
答案是我application/xml
在需要发送时发送了内容类型application/json
。