jquery - How do I code my controller action to receive data from ajax or json call? -
i trying make call controller using asp.net view. object parameter of action null. new me thought must using wrong result type. i’m using
public actionresult(object data) { return view(); } after researching feel may need use this:
public jsonresult(object data) { return something(); } my question based on script below, need have specific using statements in controller? , should action of type viewresult or jsonresult?
if jsonresult required, how code receive data ajax json code below.
<script type = "text/javascript"> $(function() { var data = [ ["", "kia", "nissan", "toyota", "honda"], ["2008", 10, 11, 12, 13], ["2009", 20, 11, 14, 13], ["2010", 30, 15, 12, 13] ]; var $container = $("#myhandsontable"); $container.handsontable({ data: data, startrows: 15, startcols: 16, rowheaders: true, colheaders: true, useformula: true, minsparecols: 1, minsparerows: 1, contextmenu: true, outsideclickdeselects: false, removerowplugin: true, useformula: true }); $container.handsontable("loaddata", data); var handsontable = $container.data('handsontable'); $("#save").click(function() { console.log(handsontable.getdata()); console.log(data); var mydata = handsontable.getdata(); mydata = json.stringify(mydata); $.ajax({ url: "/home/tabledata", type: "post", data: handsontable.getdata(), datatype: 'json', success: function(data) { alert(data); } }); }); }); </script> <button id="save">click me</button >
without seeing getdata function can assume sending key value pairs. believe need post data: {data: {}} hit controller data variable in controller. keys in js object post map parameter names of controller action.
Comments
Post a Comment