Reputation: 1851
I am working on asp.net mvc webapi with EF code first with existing database. I have a class like,
public class User
{
public bool IsAgree{get; set;}
}
Iam using MySql database, my table looks like.
--------------
|ID |IsAgree|
--------------
|int |tinyint|
--------------
and i have a post action like
public HttpReponseMessage PostUser(HttpRequestMessage request,User user)
{
// some code to handle user data..
}
and from my view i am trying to post some data to the action like,
$(document).ready(function () {
var sendata = {"IsAgree":true};
$.ajax({
url: '/api/account',
type: 'POST',
data: sendata,
dataType: "json",
contentType: "application/json; charset=utf-8",
cache: false,
success: function (data) {
alert(data.status);
},
error: function (xhr) { alert(xhr.status); }
});
});
when i put breakpoint at action it shows user as null
and i get alert message as 400
i.e. bad request. Is my json data was well for my model? Please guide me.
Upvotes: 1
Views: 1463