I'm sending an array object via ajax and C # MVC can not understand. I've tried several ways and does not work. What am I doing wrong?
I already have and without JSON.stringify, and not work. Variable teste01
receives null.
Class of object:
public class Teste
{
public int dataid {get;set;}
public string datapackage { get; set;}
public int packageid {get;set;}
}
Contoller:
[HandleError]
[AcceptVerbs(HttpVerbs.Get)]
[Authorize]
public JsonResult ListaGenerica(DataTables param, string aController, Teste[] teste01, bool porID = false, string regra = "", int filtroID = 0, string tipo = "")
JQuery functions:
function Controller()
{
return "EmpresaCarga";
}
function Dados()
{
var localproducts = [];
localproducts.push({
'dataid' : 1,
'datapackage' : 'test',
'packageid' : 3
});
localproducts.push({
'dataid' : 2,
'datapackage' : 'test 01',
'packageid' : 4
});
return localproducts;
}
JQuery:
var oTable = $('#listagem').dataTable({
"bServerSide": true,
"sAjaxSource": '@Url.Action("ListaGenerica", "Ajax")',
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "filtroID", "value": $("#ClienteID").find('option:selected').val() } );
aoData.push( { "name": "aController", "value": Controller() } );
aoData.push( { "name": "teste01", "value": Dados() } );
},
"bProcessing": true,
"sPaginationType": "full_numbers",
"aoColumns": [
{ "mDataProp": "Carga", "sTitle": "Carga" },
{ "mDataProp": "DtCarga", "sTitle": "DtCarga", "mRender": function (data, type, full) { return dtConvFromJSON(data); } },
{ "mDataProp": "Empresa", "sTitle": "Empresa" },
{ "mData": null, "bSortable": false, "mRender": function (data, type, row) { return '<a class="btn btn-default btn-xs" href="/Produto/Detalhar/' + row.EmpresaCargaID + '" title="Clique para abrir"><span class="glyphicon glyphicon-edit"></span></a>';}}
],
});
Query Strings Parameters
sEcho:2
.
.
.
filtroID:
aController:EmpresaCarga
aController:EmpresaCarga
teste01:[{"dataid":1,"datapackage":"test","packageid":3},{"dataid":2,"datapackage":"test 01","packageid":4}]
ModelState
contain any errors?List<Teste> teste01
.ModelState
Return erro: {"The parameter conversion from type 'System.String' to type 'FlexGestor.Controllers.AjaxController+Teste' failed because no type converter can convert between these types."}