javascriptc#asp.net-coreasp.net-core-mvcjquery-datatables-editor

JQuery DataTable Inline Editing With Submit Button - Post return 405 (Method Not Allowed)


I am using jquery Datatables Editor and can't quite seem to figure out the set-up of how the inline editing should go. Meaning my Controller code reads like this

[HttpGet]
[Route("api/tta")]
public JsonResult Index()
{
  var ListData = _context.TTA.FromSqlRaw("Select * from dbo.Test").ToList();
  return Json(new { Data = ListData });
}

which when I launch my asp.net core MVC append load the page the data loads exactly as expected. However, when I try the inline edit and press the submit button for the edit, I get this error in the dev console

jquery-3.3.1.js:9600 POST https://localhost:44343/api/tta 405 (Method Not Allowed)

Now from my understanding it seems that the issue is that a POST is being attempted on an API that is only set up to make a GET request. Which leads me to my question of what is the proper way to set this up so that the data will be submitted to the database successfully?

ASP.Net Core & MVC & Microsoft SQL Server if needed here is a link to the inline edit feature of DataTables https://editor.datatables.net/examples/inline-editing/submitButton.html


Solution

  • You need to create an method that accept POST request and recieve your data. Example:

    [HttpPost]
    [Route("api/tta")]
    public JsonResult Post(YourType yourParameter)
    {
      var result = MethodThatUpdateYourData(yourParameter);
      return Json(result);
    }