1. 新增或修改一條數據
1.1 添加 新增或修改按鈕
1 <div > 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 > 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>btnAddorUpdate
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 }View Code
1.3 新增或修改Controller