简体   繁体   English

使用提交按钮进行 JQuery DataTable 内联编辑 - 发布返回 405(不允许的方法)

[英]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.我正在使用 jquery 数据表编辑器,但似乎无法弄清楚内联编辑应该如何设置。 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.当我启动我的 asp.net core MVC 附加加载页面时,数据完全按预期加载。 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) jquery-3.3.1.js:9600 POST https://localhost:44343/api/tta 405(不允许的方法)

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.现在,根据我的理解,问题似乎是在仅设置为发出 GET 请求的 API 上尝试进行 POST。 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如果需要,ASP.Net Core & MVC & Microsoft SQL Server 是指向 DataTables 的内联编辑功能的链接https://editor.datatables.net/examples/inline-editing/submitButton.html

You need to create an method that accept POST request and recieve your data.您需要创建一个接受 POST 请求并接收数据的方法。 Example:例子:

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

From looking at the code given, your api/tta method allows just [HttpGet].查看给出的代码,您的 api/tta 方法只允许 [HttpGet]。 Simply add a new method with [HttpPost] which you can call to submit the data只需使用 [HttpPost] 添加一个新方法,您可以调用该方法来提交数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM