I have telerik grid on my page. But it working not correctly. Problem: when I click button edit calling method button's select. My grid view
@(Html.Telerik().Grid(Model)
.Name("Grid")
.DataKeys(keys => keys.Add(c => c.CommandId))
.DataBinding(dataBinding =>
{
dataBinding.Server().Update("Update", "CommandEntity");
dataBinding.Server().Select("Print", "CommandEntity");
dataBinding.Server().Delete("Delete", "CommandEntity");
})
.Columns(columns =>
{
columns.Bound(o => o.Date).Format("{0:dd/MM/yyyy}").Width(100);
columns.Bound(o => o.Number).Width(40);
columns.Bound(o => o.Employees).Width(240);
columns.Bound(o => o.DayCount).Width(40);
columns.Bound(o => o.Destinations).Width(220);
columns.Bound(o => o.ShortTarget).Width(200);
columns.Bound(o => o.TypeAssignment).Width(90);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Image);
commands.Delete().ButtonType(GridButtonType.Image);
commands.Select().ButtonType(GridButtonType.Image);
}).Width(100).Title("actions");
})
.Scrollable(scrolling =>
{
scrolling.Enabled(true);
scrolling.Height("500px");
})
.Editable(editing => editing.Mode(GridEditMode.PopUp))
.Sortable(sorting => sorting.Enabled(true))
.Pageable(paging =>
{
paging.Enabled(true);
paging.PageSize(15);
})
.Filterable(filtering => filtering.Enabled(true))
.Groupable(grouping => grouping.Enabled(true))
.Footer(true))
Methods:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(Guid id)
{
new DataManager().RemoveCommandEntity(id);
return RedirectToAction("Index", "CommandEntity");
}
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Print(Guid id)
{
byte[] rep = Reports.ReportBuilder.CreateReport(id);
return File(rep, System.Net.Mime.MediaTypeNames.Application.Pdf);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update(CommandEntity obj)
{
new DataManager().UpdateCommand(obj);
HttpContext.Session["Entities"] = null;
return RedirectToAction("Index", "CommandEntity");
}
should call Update method but called called Print. While there was no Select method everything worked fine. what's wrong here?
I think the problem is here:
DataBinding(dataBinding =>
{
dataBinding.Server().Update("Update", "CommandEntity");
dataBinding.Server().Select("Print", "CommandEntity");
dataBinding.Server().Delete("Delete", "CommandEntity");
})
Databinding should be used for Ajax or Web Service binding. When you want to use server binding then you simply bind to the model an then you doesn't need to use DataBinding method at all.
I think you should change this part of code to:
DataBinding(dataBinding =>
{
dataBinding.Ajax().Update("Update", "CommandEntity");
dataBinding.Ajax().Select("Print", "CommandEntity");
dataBinding.Ajax().Delete("Delete", "CommandEntity");
})
Or if you want to populate grid by server binding, then:
DataBinding(dataBinding =>
{
dataBinding.Ajax().Update("Update", "CommandEntity");
dataBinding.Ajax().Delete("Delete", "CommandEntity");
})