I’m trying to Post a List to my MVC Controller..
The Controller: // POST api/UserFollows
public HttpResponseMessage PostUserFollows(List<FollowItem> followItemList)
{
//I'M GETTING NULL IN followItemList
if(followItemList==null)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
OUTPUT:
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
The FollowItem class
namespace Helpers.SubClasses
{
public class FollowItem
{
public bool action;
public long FollowsUserId;
}
}
I tried a lot of request but none of them works.. I always get null!
THE POST METHOD:
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);
}
});
The requests: //As JSON – I’m Using 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}
]}
Example for null:

I tried a lot more..
Can anybody please help me with this?
Thanks!!!
EDIT:
The answer was that I sent application/xml in the content-type when I needed to send application/json.
The JSON doesn’t appear to be valid. Perhaps try this:
A good tool to check JSON validity is jsonlint.com.