1. 新增或修改一条数据
1.1 添加 新增或修改按钮
1 <div style=" 120px; float: right; padding-top: 3px"> 2 @Html.DevExpress().Button(settings => 3 { 4 settings.Name = "btnUpdate"; 5 settings.ControlStyle.CssClass = "button"; 6 settings.Text = "修改"; 7 settings.UseSubmitBehavior = true; 8 settings.ClientSideEvents.Click = "updateData"; 9 }).GetHtml() 10 </div> 11 12 <div style=" 120px; float: right; padding-top: 3px"> 13 @Html.DevExpress().Button(settings => 14 { 15 settings.Name = "btnAdd"; 16 settings.ControlStyle.CssClass = "button"; 17 settings.Text = "新增"; 18 settings.UseSubmitBehavior = true; 19 settings.ClientSideEvents.Click = "addData"; 20 }).GetHtml() 21 </div>
1.2 新增或修改按钮JS
1 function updateData(s, e) { 2 GridView.GetSelectedFieldValues("DocumentId", GetSelectedFieldValuesCallbackForModify); 3 } 4 5 function GetSelectedFieldValuesCallbackForModify(values) { 6 if (values.length != 1) { 7 alert("请选择一个修改项"); 8 } else { 9 $.ajax({ 10 type: "GET", 11 url: '@Url.Action("UpdateOrAdd", "Home")', 12 data: { "id": values[0] }, 13 datatype: "html", 14 ansy: false, 15 cache: false, 16 success: function (data) { 17 $('#content').html(data); 18 $("#DocumentId").val(values[0]); 19 addorUpdate.Show(); 20 }, 21 error: function () { 22 alert("处理失败!"); 23 } 24 }); 25 } 26 } 27 28 function addData(s, e) { 29 $.ajax({ 30 type: "GET", 31 url: '@Url.Action("UpdateOrAdd", "Home")', 32 data: '', 33 datatype: "html", 34 ansy: false, 35 cache: false, 36 success: function (data) { 37 $('#content').html(data); 38 addorUpdate.Show(); 39 }, 40 error: function () { 41 alert("处理失败!"); 42 } 43 }); 44 }
1.3 新增或修改Controller