In the directory Models I have this simple model:
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
In folder Controllers, which handle request, I have this:
{
// PUT: /User/Edit
[HttpPut]
public JsonResult Edit(int id, User user)
{
System.Diagnostics.Debug.WriteLine("Put request is working"); //не выполняется
return Json("Response from Edit");
}
}
And in file Index.cshtml ajax code, which is sending the HttpPut
request to controller
/*PUT*/
$.ajax({
url: '/User/Edit',
dataType: "json",
type: "PUT",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ id: 100, user: { name: 'Dmitry', email: 'dmitry@gmail.com' } }),
async: true,
processData: false,
cache: false,
success: function (data) {
alert(data); //this message does NOT work
},
error: function (xhr) {
alert('error'); //This message shows
}
});
What should I add ? POST
request with ajax, using JSON, works well, the problem is only with Put request