How do you get the new record ID when a datatable is editable (using MVC)?
How do you get the new record ID when a datatable is editable (using MVC)?
The edit feature is displayed in a modal window. When add button is clicked it saves to the MVC controller Audit/CreateAudit.
It adds the record and returns the new ID (auditID). How do I pick it up from Datatables.net code?
[code]
function DisplayAudits() {
var audit_id = GetURLParameter('id');
$('#auditList').dataTable({
"bServerSide": true,
"sAjaxSource": "@Url.Action("GetAgencyAudits", "Audit")",
"oLanguage": { "sZeroRecords": "No audits available", "sEmptyTable": "No audits available" },
"fnServerParams": function (aoData) {
aoData.push({ "name": "audit_id", "value": audit_id }
);
},
"bProcessing": true,
"iDisplayLength": 10,
"bLengthChange": false,
"bDestroy": true,
"bFilter": false,
"aoColumns": [
{ "sName": "Audit_ID",
"bSearchable": false,
"bSortable": true
},
{ "sName": "Audit_Title" },
{ "sName": "Audit_Create_Date" },
{ "sName": "Audit_Update_Date" },
{ "sName": "Audit_Status_Type" }
]
}).makeEditable({
sAddURL: "@Url.Action("CreateAudit", "Audit")",
sAddNewRowFormId: "createAuditForm",
sAddNewRowButtonId: "createAuditButton",
fnStartProcessingMode: function () {
$("#processing_message").dialog();
},
fnEndProcessingMode: function () {
$("#processing_message").dialog("close");
}
});
}
[/code]
MVC code:
[code]
public int CreateAudit(int agencyID, string auditTitle, int auditType, string[] grants)
{
AuditDAL ad = new AuditDAL();
int auditID = ad.CreateAudit(agencyID, auditTitle, auditType);
foreach (var grant in grants)
{
var grantID = Convert.ToInt32(grant);
ad.AddGrant(auditID, grantID);
}
return auditID;
}
[/code]
It adds the record and returns the new ID (auditID). How do I pick it up from Datatables.net code?
[code]
function DisplayAudits() {
var audit_id = GetURLParameter('id');
$('#auditList').dataTable({
"bServerSide": true,
"sAjaxSource": "@Url.Action("GetAgencyAudits", "Audit")",
"oLanguage": { "sZeroRecords": "No audits available", "sEmptyTable": "No audits available" },
"fnServerParams": function (aoData) {
aoData.push({ "name": "audit_id", "value": audit_id }
);
},
"bProcessing": true,
"iDisplayLength": 10,
"bLengthChange": false,
"bDestroy": true,
"bFilter": false,
"aoColumns": [
{ "sName": "Audit_ID",
"bSearchable": false,
"bSortable": true
},
{ "sName": "Audit_Title" },
{ "sName": "Audit_Create_Date" },
{ "sName": "Audit_Update_Date" },
{ "sName": "Audit_Status_Type" }
]
}).makeEditable({
sAddURL: "@Url.Action("CreateAudit", "Audit")",
sAddNewRowFormId: "createAuditForm",
sAddNewRowButtonId: "createAuditButton",
fnStartProcessingMode: function () {
$("#processing_message").dialog();
},
fnEndProcessingMode: function () {
$("#processing_message").dialog("close");
}
});
}
[/code]
MVC code:
[code]
public int CreateAudit(int agencyID, string auditTitle, int auditType, string[] grants)
{
AuditDAL ad = new AuditDAL();
int auditID = ad.CreateAudit(agencyID, auditTitle, auditType);
foreach (var grant in grants)
{
var grantID = Convert.ToInt32(grant);
ad.AddGrant(auditID, grantID);
}
return auditID;
}
[/code]
This discussion has been closed.