You are doing a POST
in your code so your API controller should have a method called Post:
public SessionAPI Post(User toRegister)
{
...
}
Question
Hello am trying to do a WebAPI + Windows Phone APP to interact. Project is Web API MVC4 .NET 4.5 I have the following issues: Model binding is not working or at last not populating internal fields.
If you try to see the variable "toRegister" from register its always null and everything null. And it should populate right?.
Note: User Object is in both cases the same class.
Server Code.
public SessionAPI register(User toRegister)
{ //SomeCodeHere }
Client Code. (Windows Phone 8)
User toPost = new User();
toPost.Name = "test";
toPost.Email = "email@email.com";
toPost.PhoneNumber = "13243";
toPost.Password = "secret";
WebClient webClient = new WebClient();
webClient.Headers["Accept"] = "application/json";
webClient.Headers["Content-Type"] = "application/json";
webClient.UploadStringAsync(new Uri(Destination), "POST" ,JsonConvert.SerializeObject(toPost));
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_UploadRegistrationCompleted);
Thank you for your time.
Solution
You are doing a POST
in your code so your API controller should have a method called Post:
public SessionAPI Post(User toRegister)
{
...
}