This question is locked. New answers and comments are not allowed.
Hi,
I have ajax binding going on in this grid ....
This is my delete action ...
This is my AjaxBindingCompany action ...
I am confused as to how I should process the delete column.
I want to set up my delete column so that when it is clicked, it shows a confirmation box, and, when it runs the action to do the delete, the screen needs to simply display without the deleted record (ajax).
My confusion lies in whether
1) I should code an ajax.actionlink in the column which just calls my std delete action and redisplays the grid (not sure how to redisplay either) ?
2) I should code the ajax.actionlink to include the "Ajax(settings => settings.Action("_AjaxBindingCompany", "Company")) " as a parameter somewhere inside the ajax.actionlink ?
3) Or, should I be using an HTML.Actionlink for this with new { @class = "t-link action-delete" }) ?
I have ajax binding going on in this grid ....
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<BCAnalytics.Models.CompanyVM>>" %> |
| <p><%= Html.ActionLink((String)Resources.BCAResources.stdClose, "Index", "Work", new { workindex = 0 }, null)%> |
| <%=Session["iqResult"]%></p> <br /> |
| <%= Html.Telerik().Grid(Model) |
| .Name("CompanyGrid") |
| .Columns(columns => |
| { |
| columns.Add(o => o.cMemberNo).Width(30) ; |
| columns.Add(o => o.cCompanyNo).Width(30); |
| columns.Add(o => o.cCompanyName).Width(175).Title((string)Resources.BCAResources.coxCompany); |
| columns.Add(o => o.cPhone).Title((string)Resources.BCAResources.stdPhone).Width(75); |
| columns.Add(o => o.cGroupCode).Title((string)Resources.BCAResources.coxGroupCode).Width(100); |
| columns.Add(o => o.cEmail).Width(120).Title((string)Resources.BCAResources.stdEmail).Width(150); |
| columns.Add(o => o.cDateUpdated).Format("{0:MM/dd/yyyy}").Width(85).Title((string)Resources.BCAResources.stdUpdated); |
| columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdEdit, "Index", "Work", new { workindex = 3, OtherParms = "{0}" }, null).ToString()).Encoded(false).Title("").Width(32); |
| // columns.Add(o => o.cCompanyNo).Format(Ajax.ActionLink("Del", "CompanyDelete", new { Id = "{0}" }, new AjaxOptions { UpdateTargetId = "CompanyGridr" })).Encoded(false).Title("").Width(50); |
| // columns.Add(o => o.cCompanyNo).Format(Ajax.ActionLink("Del", "CompanyDelete", new { Id = "{0}" }, |
| // new AjaxOptions() {}).ToString().Replace("{", "{{").Replace("}", "}}")).Encoded(false).Title("").Width(50); |
| // columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdDelete,"CompanyDelete", new { Id = "{0}" }, null).ToString()).Encoded(false).Title("").Width(50); |
| columns.Add(o => o.cCompanyNo).Format(Html.ActionLink((String)Resources.BCAResources.stdDelete, "CompanyDelete", new { Id = "{0}" }, new { @class = "t-link action-delete" }).ToString()).Encoded(false).Title("").Width(50); |
| }) |
| .Ajax(settings => settings.Action("_AjaxBindingCompany", "Company")) |
| .Pageable() |
| .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn)) |
| .Scrollable(scrolling => scrolling.Height(265)) |
| .Filterable() %> |
| <p><%= Html.ActionLink((String)Resources.BCAResources.coxFormEntry, "Index", "Work", new { workindex = 2, OtherParms = "" }, null)%></p> |
This is my delete action ...
| public ActionResult CompanyDelete(int? Id) |
| { |
| BCAEntities _dataModel = new BCAEntities(); |
| int MemberNo = Convert.ToInt32(Session["MemberNo"].ToString()); |
| var CompanyToDelete = (from m in _dataModel.Company |
| where m.coMemberNo == MemberNo && |
| m.coCompanyNo == Id |
| select m).First(); |
| if (CompanyToDelete != null) |
| { |
| try |
| { |
| _dataModel.DeleteObject(CompanyToDelete); |
| _dataModel.SaveChanges(); |
| } |
| catch (Exception exc) |
| { |
| Session["iqResult"] = "Problem deleting this entry, support has been notified"; |
| } |
| } |
| return View("Index"); |
| // return RedirectToAction("Index", "work", new { workindex = 1, OtherParms = "" }); |
| } |
This is my AjaxBindingCompany action ...
| // do the ajax binding |
| [GridAction] |
| public ActionResult _AjaxBindingCompany() |
| { |
| IEnumerable<CompanyVM> model = GetCompanies(); |
| return View(new GridModel |
| { |
| Data = model |
| }); |
| } |
| // load the viewmodel data |
| private IEnumerable<CompanyVM> GetCompanies() |
| { |
| BCAEntities bcaData = new BCAEntities(); |
| int wkMemberNo = Convert.ToInt32(Session["MemberNo"].ToString()); |
| return from o in bcaData.Company |
| where (o.coMemberNo==wkMemberNo) |
| select new CompanyVM() |
| { |
| cMemberNo = o.coMemberNo, |
| cCompanyNo = o.coCompanyNo, |
| cCompanyName = o.coCompanyName, |
| cEmail = o.coEmail, |
| cGroupCode = o.coGroupCode, |
| cPhone = o.coPhone, |
| cDateUpdated = o.coDateUpdated |
| }; |
| } |
I want to set up my delete column so that when it is clicked, it shows a confirmation box, and, when it runs the action to do the delete, the screen needs to simply display without the deleted record (ajax).
My confusion lies in whether
1) I should code an ajax.actionlink in the column which just calls my std delete action and redisplays the grid (not sure how to redisplay either) ?
2) I should code the ajax.actionlink to include the "Ajax(settings => settings.Action("_AjaxBindingCompany", "Company")) " as a parameter somewhere inside the ajax.actionlink ?
3) Or, should I be using an HTML.Actionlink for this with new { @class = "t-link action-delete" }) ?
I tried variations of all 3 but I think I may just be using the wrong syntax. i would like to use the Ajax.ActionLink for the delete, but I dont know if its more appropriate to use the HTML.Action in an ajax binding scenerio ?
thanks as always