I am making an web api in Asp.Net MVC5 with web api2. I made a post Like this:
public class SmsClientsController : ApiController
{
public void Post(Client client)
{
//Add Client to database
}
}
the Model Client is like this:
public class Client
{
public int Id { get; set; }
[Required]
public string Username { get; set; }
[Required]
public string Password { get; set; }
public int Role { get; set; }
}
and I called this post method on a button click, simply from javascript in client side like this:
function SendSms() {
var studentData = {
"Username": "Anjin",
"Password": "Pradhan",
"Role": "1"
};
$.ajax({
type: "POST",
url: "http://192.168.0.102/ProductsApp/api/SmsClients",
data: JSON.stringify(studentData),
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: true,
success: function (data, status, jqXHR) {
console.log(data);
console.log(status);
console.log(jqXHR);
alert("success..." + data);
},
error: function (xhr) {
alert(xhr.responseText);
}
});
}
But on response it just alerts a blank alert box. And when i checked the console through fire bug there was an error:
"NetworkError: 405 Method Not Allowed - http://192.168.0.102/ProductsApp/api/SmsClients"
Why is so happening?? Is this Post method invalid. Please help me to correct this...