前台JS代码
1 $("#btn_save").click(function (data) { 2 var values = $("#from_jbxx").serializeArray(); 3 var strdata = {}; 4 $.each($("#from_jbxx").serializeArray(), function (a, b) { strdata[b.name] = b.value; }); 5 if ($("#from_jbxx").validationEngine(‘validate‘)) { 6 7 $.ajax({ 8 type: ‘POST‘, 9 url: getFnDataUrl("HttpAshx/StudentInfo.ashx", "SaveStudentTurnover"), 10 data: JSON.stringify(strdata), 11 success: function (strResult) { 12 var res = $.parseJSON(strResult) || {}; 13 if (res.Succeed) { 14 alert(res.Message); 15 location.href = "/Student/UserCenter.aspx"; 16 } else { 17 alert(res.Message); 18 } 19 } 20 }); 21 return false; 22 } else { 23 return false; 24 } 25 });
后台代码
public void SaveStudentTurnover(HttpContext context) { byte[] bytes = new byte[context.Request.InputStream.Length]; context.Request.InputStream.Read(bytes, 0, bytes.Length); var values = System.Text.Encoding.UTF8.GetString(bytes).JsonDeserialize<Dictionary<string, string>>(); string strId = values["Id"] ?? ""; var model = _gdc.GetDataSet<XjStudentTurnover>().FirstOrDefault(p => p.Id == strId); if (model == null) { model = XjStudentTurnover.CreateXjStudentTurnover(_gdc.GetNewCode<XjStudentTurnover>()); model.InnerDeleteFlag = false; model.StudentId = values["StudentId"] ?? ""; _gdc.AddObject(model); } model.LoadFrom(values); _gdc.SaveChanges(); DtHttpContext.ReturnMesg(AjaxResult.Success("保存成功~!"), context); return; }
时间: 2024-10-08 10:10:21