Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: I'm working with MVC c# and Editor Datatables from http://editor.datatables.net. i'm getting the error below on line 'editor.Process(formData);' of my server code:
An item with the same key has already been added.
What could be the cause and how can i debug the error to identify what keys are being added?
Here's my code:
public class VoiceMYTABLEDataDBModel
{
public class VoiceMYTABLEData
{
public long id { get; set; }
public string Customer_ID { get; set; }
}
public class VoiceMYTABLEInvoice
{
public long id { get; set; }
public long CustomerID { get; set; }
public long MYTABLEDataID { get; set; }
public string InvoiceNumber { get; set; }
}
}
public DtResponse CRUDRatedVoiceMYTABLEData(string strFromDate, string strToDate, int intExportToFile, MYTABLEDataUISettings lblo)
{
Editor editor = null;
NameValueViewModel[] arrNVVM = null;
Task t;
try
{
HttpRequest formData = HttpContext.Current.Request;
CustomersModel CM = new CustomersModel();
arrNVVM = CM.GetAllCustomerIDsNbrs_arr();
CM = null;
if (arrNVVM == null) arrNVVM = new NameValueViewModel[] { };
using (Database db = new Database(SetGetDbType2, SetGetDbConnection))
{
editor = new Editor(db, "VoiceMYTABLEData", "VoiceMYTABLEData.id").Model<VoiceMYTABLEDataDBModel.VoiceMYTABLEData>("VoiceMYTABLEData");
editor.Field(new Field("VoiceMYTABLEData.id")
.Set(false)
);
editor.Field(new Field("VoiceMYTABLEData.Customer_ID")
.Set(false)
);
editor.LeftJoin("VoiceMYTABLEInvoice", "VoiceMYTABLEData.id", "=", "VoiceMYTABLEInvoice.MYTABLEDataID")
.MJoin(new MJoin("VoiceMYTABLEInvoice")
.Model<VoiceMYTABLEDataDBModel.VoiceMYTABLEInvoice>()
.Name("VoiceMYTABLEInvoice")
.Link("VoiceMYTABLEData.id", "VoiceMYTABLEInvoice.MYTABLEDataID")
.Order("VoiceMYTABLEInvoice.InvoiceNumber ASC")
.Field(new Field("id")
.Options(new Options()
.Table("VoiceMYTABLEInvoice")
.Value("id")
.Label("InvoiceNumber")
.Order("InvoiceNumber ASC")
.Render(row =>
{
return dicPCEAValues["InvoiceNumber"].ToString();
}).Order("InvoiceNumber ASC")
)
.Set(false)
)
.Set(false)
);
editor.Where("VoiceMYTABLEData.Date_Time_Called", CommonUtilities.ToDate2(strFromDate + " 00:00:01"), ">=");
editor.Where("VoiceMYTABLEData.Date_Time_Called", CommonUtilities.ToDate2(strToDate + " 23:59:59"), "<=");
editor.TryCatch(false);
editor.Debug(true);
editor.Process(formData);
}
arrNVVM = null;
}
catch (Exception ex)
{
}
return editor.Data();
}
function CRUDRatedVoiceMYTABLEData(strFromDate1, strToDate1, intExportToFile1) {
var strSelOpt = '';
var strSelSta = '<select class="form-control">';
var strSelEnd = '</select>';
var token = $('input[name="__RequestVerificationToken"]').val();
dataTable2 = $('#tblRatedVoiceMYTABLEDataTable').DataTable({
destroy: true,
responsive: true,
processing: true,
deferRender: true,
select: true,
order: [[0, 'desc']],
pageLength: 10,
columnDefs: [
{ 'bVisible': false, 'targets': 0 },
{
'targets': [0, 1, 2],
className: 'text-center'
}
],
dom: 'Bfrtip',
ajax: {
url: '/users/' + strAccountIdx1 + '/Admin/MYTABLEData/CRUDRatedVoiceMYTABLEData/',
data: function (d) {
return $.extend({}, d, {
strFromDate: strFromDate1,
strToDate: strToDate1,
intExportToFile: intExportToFile1,
__RequestVerificationToken: token
});
},
//type: 'GET',
type: 'POST',
dataType: 'json',
//contentType: 'application/json; charset=utf-8',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
async: true,
cache: false
},
columns: [
{
data: 'VoiceMYTABLEData.id',
className: 'text-left'
},
{
data: 'VoiceMYTABLEData.Customer_ID',
className: 'text-left'
},
{
data: 'VoiceMYTABLEInvoice',
className: 'text-left'
}
],
buttons: [
{ extend: 'edit', editor: editor3, formButtons: [] }
]
});
}
- create script for the db tables:
CREATE TABLE IF NOT EXISTS `[DBNAME]`.`VoiceMYTABLEData` (
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`Customer_ID` BIGINT DEFAULT '0',
PRIMARY KEY (`ID`),
UNIQUE INDEX `Index_PrimaryKey` (`ID`),
INDEX `Index_Customer_ID` (`Customer_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `[DBNAME]`.`VoiceMYTABLEInvoice`;;
CREATE TABLE IF NOT EXISTS `[DBNAME]`.`VoiceMYTABLEInvoice` (
`ID` BIGINT NOT NULL AUTO_INCREMENT,
`CustomerID` BIGINT DEFAULT '0',
`MYTABLEDataID` BIGINT DEFAULT '0',
`InvoiceNumber` VARCHAR(55) DEFAULT NULL,
PRIMARY KEY (`ID`),
UNIQUE INDEX `Index_PrimaryKey` (`ID`),
INDEX `Index_CustomerID` (`CustomerID`),
INDEX `Index_MYTABLEDataID` (`MYTABLEDataID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide