Datatable Editor in C# MVC Environnement
Datatable Editor in C# MVC Environnement
I'am trying to include an editing function on a Datatables (single line) in c# MVC environment.
in my controller, I want to receive two vars: action (edit on this case) and the data fields.
When I update a data, my action in controller is called, and It works for "action". Unfortunately, data it always null. I already tried array, string, I also tried to create one var by field...
Could you help me? What the type of the data var? Have I to add anythiong on ma jquery code?
My code:
Controller Action called when update:
public ActionResult UpdateData(string action, object data)
{
........
}
_**
code in View file**_
@using CASSIOPEE.Resources;
@{
ViewBag.Title = "Listing";
}
<h2>Résultat de la recherche</h2>
<table class="display" id="myTable">
<thead>
<tr>
<th></th>
<th>Id</th>
<th>Numero</th>
<th>Nom</th>
<th>Bailleur</th>
<th>Type Aff</th>
<th>Pays</th>
<th>Date OEI</th>
</tr>
</thead>
</table>
@*Chargement de Datatable*@
<script>
$(document).ready(function () {
console.log("@Url.Action("loadData")");
editor = new $.fn.dataTable.Editor({
"ajax": "@Url.RouteUrl(AppSharedValues.AjaxRouteName, new { controller="Recherche", action= "UpdateData" })",
"idSrc": "id",
"table": "#myTable",
"fields": [{
"label": "Id:",
"name": "id"
}, {
"label": "numAffaire:",
"name": "numAffaire"
}, {
"label": "numProjet:",
"name": "numProjet"
}, {
"label": "bailleurProcede:",
"name": "bailleurProcede"
}, {
"label": "typeAffaire:",
"name": "typeAffaire"
}, {
"label": "pays:",
"name": "pays"
}, {
"label": "dateOEI:",
"name": "dateOEI",
"type": "datetime"
}
]
});
$('#myTable').dataTable({
"dom": "Bfrtip",
"ajax": {
"url": "@Url.RouteUrl(AppSharedValues.AjaxRouteName, new { controller="Recherche", action= "loadDataNew" })",
@*"url": "@Url.Action("loadData")",*@
"type": "GET",
"datatype":"json"
},
"oSearch": {"sSearch": "@ViewBag.defaultSearchField"},
"columns": [
{
"data": null,
"defaultContent": "",
"className": "select-checkbox",
"orderable": false
},
{ "data": "id", "autoWidth": true },
{ "data": "numAffaire", "autoWidth": true },
{ "data": "numProjet", "autoWidth": true },
{ "data": "bailleurProcede", "autoWidth": true },
{ "data": "typeAffaire", "autoWidth": true },
{ "data": "pays", "autoWidth": true },
{ "data": "dateOEI", "autoWidth": true }
],
"select": true,
"buttons": [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
],
"aLengthMenu": [[25, 50, 75, -1], [25, 50, 75, "All"]],
"iDisplayLength": 25
});
});
</script>
Thanks
Florian