PDF.NET+EasyUI实现只更新修改的字段

PDF.NET 在我看来是目前最简单易用而且高效的orm框架之一,感谢作者深蓝医生

实现的功能是easyui的行内编辑,用到了爱看书不识字的datagrid仿extjs的行内编辑 都是牛人啊。

2014/2/15使用Json.net和json2修改

下面是js代码

onAfterEdit: function (index, data, changes) {
                    $.parser.parse();
                    $('#videoGrid').datagrid('fixRowHeight', index);
            var postdata=$.extend(changes,{Vide_Id: data.Vide_Id}) easyAjax({ url: actionUrl
+ '?action=update', data: {model:JSON.stringify(postdata)}, success:function (){} }); },

easyAjax是一个封装的ajax访问请求,大家可以换成jquery的就行。
onAfterEdit里有三个参数,changes为当前修改的字段对象 $.extend(changes,{Vide_Id:data.Vide_Id})把主键添加到data里

2014/2/15hanlder里代码使用Json.net简化代码

string model = context.Request["pQuestion"];

var pQuestion = JsonConvert.DeserializeObject<tbTestPaperQuestionsModel>(model);

paperQuestionsBll.AddPaperQuestion(pQuestion, needAddChild);

下面是handler的代码

private void UpdateVideo(HttpContext context)
        {
       string model=context.Request["model"]
       var model=JsonConvert.DeserializeObject<tbVideoModel>(model);
       bool result=newVideoBll.Update(model);
//以下为之前旧代码
//Dictionary
<string, string> changes = new Dictionary<string, string>(); //foreach (var key in context.Request.Form.Keys) //{ // string keyName = key.ToString(); // string keyValue = context.Request.Form[keyName]; // changes.Add(keyName, keyValue); //} //bool result = newVideoBll.UpdateNewVideo(changes); context.Response.Write(AjaxResult.Success("成功")); }

看下最后生成的sql语句 UPDATE [tbNewVideoInfo] SET [Vide_Reminds]=@P0 WHERE [Vide_Id]=@P1

你前台修改了什么字段,后台就生成对应的sql语句 很爽把。

更多的PDF.NET资料请移步深蓝医生博客http://www.cnblogs.com/bluedoctor/

菜鸟,真心菜鸟。轻喷


真正的认识自己,才能做好自己,做好自己,才能做好你将会做的每一件事。
原文地址:https://www.cnblogs.com/encore620/p/3197117.html