POSTAPIコントローラーを呼び出そうとしています。コントローラは呼び出されますが、複雑なオブジェクトは空になります。私はFiddlerを実行しましたが、オブジェクトはそこに入力されています。私は何が間違っているのですか?
私のC#オブジェクト
public class RegisterUser
{
public Guid PersonId { get; set; }
public string Email { get; set; }
public string Business { get; set; }
public string EmployeeNumber { get; set; }
public string UserName { get; set; }
}
APIポストコントローラー
public HttpResponseMessage Post(RegisterUser user)
{
//This is where the problem is. Everything in user is null
//even though I can see it coming through on Fiddler.
}
Javascriptコード
function User(personId, userName, email, business, employeeNumber) {
this.PersonId = personId;
this.Email = email;
this.Business = business;
this.EmployeeNumber = employeeNumber;
this.UserName = userName;
}
function RegisterUser(url) {
var createdUser = new User("b3fd25ba-49e8-4247-9f23-a6bb90a62691", "username", "email", "business", "56465");
$.ajax(url, {
data: JSON.stringify({ user: createdUser }),
type: "post",
contentType: "application/json"
});
}
WebAPIルート構成
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "RegisterApi",
routeTemplate: "api/{controller}/{user}"
);
}
}