How to post custom content on delete?
How to post custom content on delete?
For editor updates (i.e., when it POSTs to the server), I have successfully implemented passing a custom form element called DatabaseName. I do this by adding to the editor upon initialization:
editor = new $.fn.dataTable.Editor({
...
}).add({
name: "DatabaseName=" + (dbName || $(".ddlDatabases").val())
});
However, when I select a row and click the Delete button, it POSTs to the server BEFORE opening a dialog box (which contains a div with class "DTE_Action_Remove" which contains a nested Delete button). When it POSTs to the server BEFORE the delete dialog pops up, it DOES contain the custom DatabaseName element, but nothing actually happens on the server (until after the confirmation).
But, when I confirm the delete prompt by clicking the Delete button on the dialog, it POSTs to the server a second time. This is the action that is supposed to perform the actual delete, but on the second POST it no longer contains my custom element. How can I re-add my custom element to the actual POST action that performs the delete upon confirmation?
I have tried calling this on the ".DTE_Action_Remove button" click event, but it doesn't work:
editor.add({
name: "DatabaseName=" + (dbName || $(".ddlDatabases").val())
});
This question has an accepted answers - jump to answer
Answers
Could you show me the full Editor and Editor API code you are using please? Specifically I need to know how you are calling the
remove()
method since by default it will show the lightbox before sending anything to the server.Generally I would suggest using
ajax.data
orpreSubmit
to add data to the object Editor sends to the server.Thanks,
Allan
Actually, that was the first thing I tried, using the ajax.data, that is. However, it causes the New/Edit (INSERT/UPDATE) to fail.... with/without an error, depending on whether I pass this data as plain text or serialized JSON. However, when I simply remove ajax.data, it works as expected.
I have indicated 3 lines of code that should be alternately uncommented to try various configurations. These places are where you will find "/* TODO:" comment blocks.
If I do add ajax.data, yes, it does properly pass custom arguments to the server, which can be found in HttpContext.Current.Request.Form (C#). But the unwanted side-effect of it causing New/Edit/Delete to fail must then be overcome. Suggestions?
BTW, this code has a bit of a legacy feel due to the server code being in a VB.NET ASMX web service. As such, I had to add function parseData to retrieve the pure JSON so it could be consumed by Datatables editor. You may wish to just remove that dataFilter. NOTE: This is very unlikely to be the cause of any problems because everything works if I merely do NOT post data in the ajax.data.
Code will be forthcoming, due to size limits on Post Comment
JS Code
JS Code PART II
C# Code
HTML
Use this for your
ajax.data
:As you will see from the
ajax.data
examples you need to modify the data that Editor wants to submit to the server. Otherwise Editor's data wouldn't be sent, and yes, the action would fail.Allan
Yes, that's the trick. Thank you, sir.