Im using SlickGrid and was tying to add data from grid to the DB when the user press the Enter key. It is sendig and JSON object (e.g. {"name":"value"}
) and I need it as an array since im using type 'System.Collections.Generic.List'. Is its possible, in the controller , change it to a JSON array ?
The data is obtained from the grid itself.
Thanks in advance!
I've seen some similar situations but Im still gettint the error :
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[DAL.SlickGridTest]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
this is my action public ActionResult EditGridEnter(string mydata)
and this is my jquery $.post
grid.onKeyDown.subscribe(function(e) {
var keyPressed = event.keyCode || event.which;
if (keyPressed == 13) {
var myJSON = JSON.stringify(item);
$.post("/SlickGridTest/EditGridEnter", $("input[name=mydata]").val(myJSON));
}
});
This is what comes from item :
var idData = jsonResult[key].id + 1;
var item = { "id": idData, "t_nome": "", "t_prof": "", "t_data": "", "t_morada": "", "t_percCompleto": "" };
all data comes from the grid in slickgrid
This is how I deserialize the object:
var slcgrd= JsonConvert.DeserializeObject<List<SlickGridTest>>(mydata);
I expect to get values as an array (e.g. [1,2,3]
) and im getting as object ( Object {id: 43, t_nome: "name name", t_prof: "prof", …} )