存储更新LINQ查询并传递给json

我正在尝试创建更新linq查询并使用jQuery生成表,因此在更新后如何保存对表中数据的更改?

JQUERY

现在我从表中获取ServiceID,并尝试在ServiceID的基础上更新记录

我试试这个

$(function () { $('#services_schdulue').on('click', 'tr', function () { debugger; var row = $(this); var ServiceID = row.find('td')[0].firstChild.data; var s = {}; s.ServiceID = ServiceID; $('[ID*=btn_update]').on('click', function () { debugger; var ServiceID = s.ServiceID; var frequency = $('#txt_repeat').val(); var Freq_Du = $('#dura_values').val(); var Freq_Mil= $('#text_mil').val(); debugger; var obj = {}; obj.ServiceID = ServiceID; obj.frequency = frequency; obj.Freq_Du = Freq_Du; obj.Freq_Mi= Freq_Mil; updatedata(obj); }); }); } alert("12-1"); function updatedata(obj) { $.ajax({ type: "POST", url: "Maintenance.aspx/updateselect_data", contentType: "application/json;charset=utf-8", data: "{'ServiceID':'" + obj.ServiceID + "','frequency':'" + obj.frequency + "','Freq_Du':'" + obj.Freq_Du + "','Freq_Mil':'" + obj.Freq_Mil + "'}", dataType: "json", async: true, cache: false, success:function(result) { alert("15-1"); debugger; var up = JSON.parse(result.d).response; $("#txt_repeat" + obj.frequency).html(obj.frequency); $("#dura_values" + obj.Freq_Duration).html(obj.Freq_Duration); $("#text_mil" + obj.Freq_Mileage).html(obj.Freq_Mileage); $("#text_mil" + obj.frequency + obj.Freq_Duration + obj.Freq_Mileage).html(obj.frequency + obj.Freq_Duration + obj.Freq_Mileage); }, error: function (error) { var r = error.responseText; var errorMessage = r.Message; alert(errorMessage); alert(r); alert("error") } }); } 

像这样的数据库表中的数据

  Service ID frequency Freq_Du Freq_Mil 1 2 month 1200 

我在这样的页面中显示数据

  Service ID Info 1 2 month 1200 

现在,当我更新此记录更改反映在数据库表中但不反映在我在页面中显示的表中

我在这样的1个单元格中连接数据

  var example = $("#services_schdulue").DataTable({ "dom": 'Blfrtip', "columns":[ { "title": "Service ID", "data": "Service ID" },{ "title": "frequency", "data": "frequency", "visible": false }, { "title": "Freq_Du", "data": "Freq_Du", "visible": false },{ "title": "Freq_Mil", "data": "Freq_Mil", "render": function(data, type, row){ return row.frequency + row.Freq_Du+ row.Freq_Mil } }, 

您的参数不匹配。 在您的web方法中,方法签名需要

  int ServiceID, string frequency, string Freq_Du, and string Freq_Mil 

在你的ajaxpost中

 data: "{'SID':'" + obj.ServiceID + "','frequency':'" + obj.frequency + "','Freq_Du':'" + obj.Freq_Du + "','Freq_Mil':'" + obj.Freq_Mil + "'}". 

data: "{...}"只会将一个字符串传递给你的updateselect_data(int, string, string, string) 。 不要指望你的电脑太多。 它不知道如何在没有显式指令的情况下将字符串转换为int。