in the Models folder there is such a simple model:

public class User { public int Id { get; set; } public string Name { get; set; } public string Email { get; set; } } 

In the UserController controller that processes the request, the following code is written:

 public class UserController : Controller { // 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 sending the request from the Index.cshtml file

 /*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); //это не работает }, error: function (xhr) { alert('error'); //срабатывает эта строка } }); 
  • Add error information to question - Andrew B
  • error: function (xhr, ajaxOptions, thrownError) {alert (xhr.status); alert (thrownError); } Issues: 404 Not Found - Dmitry

1 answer 1

Solved the problem by adding such a block to the Web.config file after the <system.webServer>

 <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers>