Cannot delete row from MVC Gird - Null value passed to Controller

Using the MVC Grid with Allow delete and delete and delete toolbar does not pass key nor object to the RemoveUrl of the controller.
The value passed is always null. As a result one cannot use the key value to lookup the row to delete it.
See Test code below:
View
@using R3Risk.Web.Controllers;
@{
ViewBag.Title = "Test";
}

Test

@(Html.EJ().Grid("Test")
.Datasource(ds => ds
.RemoveURL("RowDelete")
.Adaptor(AdaptorType.RemoteSaveAdaptor)
.Json((IList)ViewBag.DataSource)
)
.AllowSelection()
.EditSettings(edit => { edit.AllowDeleting().EditMode(EditMode.Normal); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Delete);
});
})
.Columns(col =>
{
col.Field(p => p.Id).IsPrimaryKey(true).Visible(true).Add();
col.Field(p => p.Name).HeaderText("Name").Add();
}
))
Controller and Model
using System.Collections.Generic;
using System.Web.Mvc;
namespace R3Risk.Web.Controllers
{
public class TestController : Controller
{
public ActionResult Index()
{
var tr = new List
{
new TestObject {Id=1, Name = "one"},
new TestObject {Id=2, Name = "two"},
new TestObject {Id=3, Name = "three"},
new TestObject {Id=4, Name = "four"},
new TestObject {Id=5, Name = "five"},
new TestObject {Id=6, Name = "six"}
};
ViewBag.DataSource = tr;
return View();
}
public ActionResult RowDelete(int Id=-1)
{
return View();
}
}
public class TestObject
{
public int Id { get; set; }
public string Name { get; set; }
}
}
Thanks
Robert

1 Reply

VA Venkatesh Ayothi Raman Syncfusion Team October 16, 2017 06:26 AM UTC

Hi Robert, 

Thanks for using Syncfusion products. 

We went through your code example that you have shared for us and found that you are passing the wrong parameter in “RowDelete” action in controller. We have passed the corresponding primary key value as parameter as named “key”. This is the cause of this issue and we suggest you to use Key parameter in “RowDelete” action instead of Primary key field value “Id” like as follows, 
Code example
public ActionResult RowDelete(int Key) 
{ 
 
//do stuff 
} 
 

Refer to the following UG documentation and online demo for more information, 

Regards, 
Venkatesh Ayothiraman. 


Loader.
Up arrow icon