Grid remove not working

Selecting a row then clicking delete from the toolbar - it enters the ActionResult Remove but the passed data is blank - the ID is 0, rest of data is null.  What is the issue?

Here is the view.



    @(Html.EJ().Grid<Object>
    ("FlatGrid")
    .Datasource(ds => ds.URL("GetData").UpdateURL("Update").RemoveURL("Remove").Adaptor(AdaptorType.UrlAdaptor))
    .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Normal); })
    .ToolbarSettings(toolbar =>
    {
    toolbar.ShowToolbar().ToolbarItems(items =>
    {
    items.AddTool(ToolBarItems.Add);
    items.AddTool(ToolBarItems.Edit);
    items.AddTool(ToolBarItems.Delete);
    items.AddTool(ToolBarItems.Update);
    items.AddTool(ToolBarItems.Cancel);
    });
    })
    .Columns(col =>
    {
    col.Field("ID").HeaderText("ID").IsPrimaryKey(true).Visible(false).TextAlign(TextAlign.Left).Add();
    col.Field("person_id").HeaderText("person_id").Visible(false).TextAlign(TextAlign.Left).Add();
    col.Field("task_id").HeaderText("task_id").Visible(false).TextAlign(TextAlign.Left).Add();
    col.Field("first_name").HeaderText("first_name").AllowEditing(false).TextAlign(TextAlign.Left).Type("string").Add();
    col.Field("last_name").HeaderText("last_name").AllowEditing(false).TextAlign(TextAlign.Left).Type("string").Add();
    col.Field("DOB").HeaderText("DOB").AllowEditing(false).TextAlign(TextAlign.Left).Type("datetime").Add();
    col.Field("task_create_timestamp").HeaderText("task_create_timestamp").AllowEditing(false).TextAlign(TextAlign.Left).Type("datetime").Add();
    col.Field("referral_acquired").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>
        )ViewBag.dropData).Width("12%").Add();
    col.Field("auth_acquired").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>
        )ViewBag.dropData).Width("12%").Type("string").Add();
    col.Field("handp_acquired").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>
        )ViewBag.dropData).Width("12%").Type("string").Add();
    col.Field("ascan_acquired").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>
        )ViewBag.dropData).Width("12%").Type("string").Add();
    col.Field("other_acquired").EditType(EditingType.DropdownEdit).DataSource((IEnumerable<object>
        )ViewBag.dropData).Width("12%").Type("string").Add();

    })
    .ClientSideEvents(eve => { eve.QueryCellInfo("querycellinfo"); eve.RowSelected("onRowSelected"); } )
    )


Here is the controller:

public ActionResult Remove(NextGenTask value)  //the value param only contains a entity with values that only appear in grid (the rest are null), NOT the original entity with updated values.
        {
            NextGenTask req = db.NextGenTasks.Single(o => o.ID == value.ID);
            db.Entry(req).State = EntityState.Deleted;
            //req.BU = value.BU;
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }
            var result = db.NextGenTasks.ToList();
            return Json(new { result = result, count = result.Count }, JsonRequestBehavior.AllowGet);
        }


3 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team October 19, 2018 10:46 AM UTC

Hi Robert, 
 
Thanks for contacting Syncfusion support. 
 
Query: Deleting record is not working proper. 
 
As per your given code example we have prepared a sample. But we are unable to reproduce the reported issue at our end.  
 
Refer the below link for sample and video demo, 
 
After referring the sample still facing the issue please get back to us with the following details, 
  1. From your code example, we could see that you used RowSelected event. Please share that detail.
  2. Share the network tab detail for the ajax post when we delete the record.
  3. Share the Essential studio version.
  4. Share the Complete grid code example.
  5. If possible reproduce the issue in the provided sample and revert us back.
 
Regards, 
Thavasianand S. 



RD ROBERT DEJOURNETT October 19, 2018 12:25 PM UTC

Hi thanks much, I was able to fix the problem due to your sample.  The remove Action is passed an int instead of the object as shown below.  This can be used with Entity framework.

        public ActionResult Remove(int key)  //the value param only contains a entity with values that only appear in grid (the rest are null), NOT the original entity with updated values.
        {
            NextGenTask req = db.NextGenTasks.Single(o => o.ID == key);
            db.Entry(req).State = EntityState.Deleted;
            //req.BU = value.BU;
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }
            var result = db.NextGenTasks.ToList();
            return Json(new { result = result, count = result.Count }, JsonRequestBehavior.AllowGet);
        }




SE Sathyanarayanamoorthy Eswararao Syncfusion Team October 22, 2018 04:34 AM UTC

Hi Robert, 

Thanks for the update. We are happy to hear that your issue has been resolved. 

If you need any further assistance, please get back to us. We will be happy to assist you. 

Regards, 
Sathyanarayanamoorthy 


Loader.
Up arrow icon