- Home
- Forum
- ASP.NET MVC
- Delete grid line using multiple primary key
Delete grid line using multiple primary key
Thanks for using Syncfusion products.
We can achieve your requirement “get all primary key values to get the data” by passing the additional key values using the Headers of the ejDataManager. While performing delete action in the actionBegin event, add the required number of array of objects into Headers and retrieve them using the Request Object of the HttpRequestMessage.
|
@(Html.EJ().Grid<emp.Models.UseDocLineModel>("FlatGrid") .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.dataSource).UpdateURL("Update").InsertURL("NormalInsert").RemoveURL("DeleteLine").Adaptor(AdaptorType.RemoteSaveAdaptor)) . . . . . . . . .ClientSideEvents(eve => { eve.ActionBegin("begin").ActionComplete("complete");}) ) <script type="text/javascript"> function begin(args) { if (args.requestType == 'delete') { args.model.dataSource.dataSource.headers = []; args.model.dataSource.dataSource.headers.push({ "additional_key": args.data.document_code, "additional_key1": args.data.document_no, "additional_key2": args.data.line_no });
} } function complete(args) { if (args.requestType == 'delete') args.model.dataSource.dataSource.headers = [];//to avoid headers value to be interfered with other actions, emptied the Headers } //Perform delete public ActionResult DeleteLine(int key //primarykey value) {
NORTHWNDEntities db = new NORTHWNDEntities(); //getting additional key values string obj = Request.Headers.GetValues("additional_key")[0]; //key1 int obj1 = Int32.Parse(Request.Headers.GetValues("additional_key1")[0]); //key2 int obj2 = Int32.Parse(Request.Headers.GetValues("additional_key2")[0]); //key3 . . . . . . . . //code for delete the record return Json(docLines, JsonRequestBehavior.AllowGet); |
We have already discussed about “how to pass custom headers to server through datamanager” in the below link,
https://www.syncfusion.com/kb/5963/how-to-send-custom-headers-to-server-using-datamanager
Regards,
Gowthami V.
Try the solution and get back to us if you need further assistance.
Regards,
Gowthami V.
No. The last primary key column value will be passed to the Delete controller method as a key parameter.
Refer to below screenshot (OrderID, EmployeeID and Freight fields are PrimaryKey field)
Grid
Delete method
Regards,
Gowthami V.
We have already discussed about the topic “Displaying error message if server action failed” in the below KB document,
https://www.syncfusion.com/kb/5170/how-to-display-custom-error-message-on-ajax-action-failture
Regards,
Gowthami V.
- 8 Replies
- 3 Participants
-
SS Shanzida Sharaf
- Feb 24, 2016 07:32 AM UTC
- Mar 7, 2016 08:36 AM UTC