We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Delete Method with Composite Key

Thread ID:

Created:

Updated:

Platform:

Replies:

121571 Jan 4,2016 04:40 AM UTC Jan 6,2016 04:24 AM UTC ASP.NET MVC 3
loading
Tags: Grid
Todd M
Asked On January 4, 2016 04:40 AM UTC

I have a a table with a Composite Key (int, int, string).  I have working code for a standard table (1st below) modified to work with the Composite key (2nd below). However when I press the delete icon nothing happens. Code breaks in the method don't even register that the method is being called. Is the something in the grid a can modify or do I need a new approach? Thanks.

Working code (with standard Primary Key)
        public ActionResult Delete(int key)
        {
            Result result = db.Result.Find(key);
            db.Result.Remove(result);
            db.SaveChanges();
            return Json(GetResults(), JsonRequestBehavior.AllowGet);
        }

Attempted code (with Composite Key)
        public ActionResult Delete(int key0, int key1, string key2)
        {
            Result result = db.Result.Find(key0, key1, key2);
            db.Result.Remove(result);
            db.SaveChanges();
            return Json(GetResults(), JsonRequestBehavior.AllowGet);
        }

Gowthami V [Syncfusion]
Replied On January 5, 2016 12:20 PM UTC

Hi Todd,

Thanks for using Syncfusion products.

We can achieve your requirement 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. 

Refer to the below code example,

@(Html.EJ().Grid<OrderTable>("Grid")

        .Datasource(ds => ds.URL("GetOrderData")

                            . . . .

                            .RemoveURL("PerformDelete")

                            .Adaptor(AdaptorType.UrlAdaptor)
                            )
. . . .
. . . .

.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.EmployeeID,"additional_key1":args.data.CustomerID });

          

        }

    }

    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 

    }
    </script>

//Perform delete

        public ActionResult PerformDelete(int key //primarykey value)

        {


            NORTHWNDEntities db = new NORTHWNDEntities();

            //getting additional key values

            int obj = Int32.Parse( Request.Headers.GetValues("additional_key")[0]); //key1

            string obj1 = Request.Headers.GetValues("additional_key1")[0]; //key2

            . . . .

            . . . .

            db.SaveChanges();

            return RedirectToAction("GetOrderData");

        }


Refer to the below screenshot for more clarification,




Regards,

Gowthami V.

Todd M
Replied On January 5, 2016 03:18 PM UTC

Thank you. I got it working with a slight modification. I noticed that the "delete" method would only be called IF the value was a pure numeric string (e.g. 1000), if the value was 11B then the method wouldn't even be called.  I changed the method argument from int key to string key.  Works great.

Ragavee U S [Syncfusion]
Replied On January 6, 2016 04:24 AM UTC

Hi Todd,

Thanks for your update.

We are happy that your requirement is achieved.

Regards,
Ragavee U S

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;