editor: submit data using different HTTP method
editor: submit data using different HTTP method
emilsonpineda@hotmail.com
Posts: 3Questions: 2Answers: 0
Hi,
i'm try to send data to server using a custom method to pass the field name and new value, and i don't know why don't work.
I get this error: PUT http://localhost:61245/Employees/SaveEditedField/1 404 (Not Found).
i'm try to use this code:
editor = new $.fn.dataTable.Editor({
idSrc: "id",
table: "#example",
fields: [
{ label: "Código:", name: "code" },
{ label: "Nombre(s)", name: "names" },
{ label: "Apellido(s)", name: "lastNames" },
{ label: "Identidad", name: "personalId" },
{ label: "Fecha Nacimiento:", name: "birthday" }
],
ajax: {
create: '/Employees/GetAll',
edit: {
type: 'PUT',
contentType: 'application/json',
url: '/Employees/SaveEditedField/_id_',
data: function(d) {
$.each(d.data, function (key, value) {
$.each(value, function (a, b) {
var retStr = '{"Field":"' + a + '", "Value":"' + b + '"}';
return JSON.stringify(retStr);
});
});
}
},
remove: '/Employees/GetAll'
}
});
and i have this in the controller:
public class EmployeesController : Controller
{
public ActionResult Index() {
return View();
}
public JsonResult GetAll() {
}
public JsonResult SaveEditedField(string id, string Field, string Value) {
return Json(null);
}
}
I using VS2015 ASP.NET MVC. Could you help me please?
Best regard,
This discussion has been closed.
Answers
I can't really help much with the routing aspect of ASP.NET MVC, but it certainly sounds like the issue is there.
It looks like your controller is expecting three parameters, but only the ID is being sent. I think if you remove the field and values from the
SaveEditedField
method it might at least trigger that method and you can then access the submitted information from the request body. But I'm not an ASP.NET routing expert by any means!Allan
hi Allan, thanks for your answer, i was testing and to the change the property "type" to "POST" and started to work good, now i have a couple of doubts or suggestions that could serve to improve.
Best regards.