neel k

neel k

  • NA
  • 143
  • 137k

not deleting a row using Kendo grid in mvc 5

Feb 3 2015 10:51 AM
In MVC 5 application I am using Kendo grid. In that I insert delete button column , when I click the delete button in one row that entire row deleted from the grid not deleting from database when I refresh the page that deleted record still display in grid.
This is my view:
@(Html.Kendo().Grid(Model)
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.ad_user_id).Title("User").HeaderHtmlAttributes(new { style = "font-size:20pt;" });
columns.Bound(c => c.title).Title("Title Description").HeaderHtmlAttributes(new { style = "font-size:20pt;" });
columns.Bound(c => c.date_created).Title("Created Date").HeaderHtmlAttributes(new { style = "font-size:20pt;" });
columns.Command(command => command.Destroy()).Width(110);
//columns.Template(e => { }).ClientTemplate("<img src='Content/images/delete.png'/>").Width(140);
})
.HtmlAttributes(new { style = "height: 380px;" })
.Scrollable()
.Groupable()
.Sortable(sortable => sortable.AllowUnsort(true).SortMode(GridSortMode.MultipleColumn))
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.PageSize(20)
.Batch(true)
.Model(model => model.Id(p => p.ad_user_id))
.Destroy(delete => delete.Action("Remove", "ExternalApplications"))
.Read(read => read.Action("ViewChangeLogs", "ExternalApplications"))
)
)
 
Controller code:
public ActionResult Remove(int? id, [DataSourceRequest] DataSourceRequest request, SP_ManageUsers_Result user)
{
var appEdit = GetApplicationDetailsByAppId(id);
if (user != null && ModelState.IsValid)
{
tbl_EA_AppUsers appUser = (from u in db.tbl_EA_AppUsers
where (u.appid == id)
select u).Single();
db.tbl_EA_AppUsers.Remove(appUser);
db.SaveChanges();
}
return Json(ModelState.ToDataSourceResult());
}
 
And how to add an delete image instead of delete button. when i click the delete image record will delete from grid and database also. this is my actual requirement. 
 
this is very urgent.
 
thank you,