I want to update record in database by using WEB API Controller
// PUT api/Student/5
[HttpPut]
public HttpResponseMessage PutStudent(int id, [FromBody]Student student)
{
//body
}
then how should I call this method using jquery ajax put method?
How to use PUT method using AJAX to call WEB API controller
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Tanmay Mule24 pointsPosted Feb 11, 2015, 2:09 AM EST
even the execution doesn't reach to my controllers method
Pranay RanaRank #732 · 3.2K pointsPosted Feb 11, 2015, 2:12 AM EST
Tanmay Mule24 pointsPosted Feb 11, 2015, 2:26 AM EST
Pranay RanaRank #732 · 3.2K pointsPosted Feb 11, 2015, 1:49 AM EST
var student = new Object();
student =
{
FirtName : 'John',
LastName : 'Smith'
};
$.ajax(
{
url: 'api/Student/PutStudent/' + id,
type: 'Put',
contentType : "application/json"
data: JSON.stringify(datasend),
dataType: "json",
success: function(result)
{
// Do something with the result
}
});
Type: String
The type of request to make (e.g. "POST", "GET", "PUT"); default is "GET".
Check jquery document : http://api.jquery.com/jQuery.ajax/#options for more details
1 short reply
Pranay RanaRank #732 · 3.2K pointsPosted Feb 11, 2015, 2:04 AM EST