This question is locked. New answers and comments are not allowed.
I'm having trouble with an AJAX POST. I'm defining where I want the AJAX call to be posted, but it's posting elsewhere. Please help.
I'm using an MVC Telerik Grid. I'm following the example at http://demos.telerik.com/aspnet-mvc/razor/grid/editingbatch
From that example, Important pieces to this Grid puzzle include:
Also from that example, defining the url for the AJAX call:
For both `Select()` and `Update()` methods, the first parameter is the Action and the second parameter is the Controller. I have a third optional parameter which contains the other data to send back in the post.
My grid is Master/Detail. I've taken out the Detail portion and I'm still having the issue. I've giving you my entire grid. For now please let's focus on the Master portion.
My `Select()` method calls correctly, however my `Update()` method does not. It simply posts to the same page the grid resides on. I had this working but didn't bother to check in (stupid), and broke it a few days later. No amount of Ctrl+Z has helped me.
Here is the action in my Ajax Controller. Details removed since they don't matter. The method just isn't getting called.
When I click the Save button in my grid's toolbar, I can use firebug to see the `Select()` method makes the proper AJAX call but the `Update()` method doesn't: (See http://i.stack.imgur.com/GPCS6.png)
In this image the first post url corresponds with the values passed into my `Select()` method. The second post url does not correspond with my `Update()` method.
What's going on here? Thanks in advance
I'm using an MVC Telerik Grid. I'm following the example at http://demos.telerik.com/aspnet-mvc/razor/grid/editingbatch
From that example, Important pieces to this Grid puzzle include:
.Editable(editing => editing.Mode(GridEditMode.InCell))Also from that example, defining the url for the AJAX call:
.DataBinding(dataBinding => dataBinding.Ajax() .Select("_SelectContactsBatchEditing", "Ajax", new {FirstName = @ViewData["FirstName"], LastName = @ViewData["LastName"]}) .Update("_SaveContactsBatchEditing", "Ajax", new {FirstName = @ViewData["FirstName"], LastName = @ViewData["LastName"]}) )For both `Select()` and `Update()` methods, the first parameter is the Action and the second parameter is the Controller. I have a third optional parameter which contains the other data to send back in the post.
My grid is Master/Detail. I've taken out the Detail portion and I'm still having the issue. I've giving you my entire grid. For now please let's focus on the Master portion.
@(Html.Telerik().Grid<ContactView>() .Name("ContactsGrid") .Columns(columns => { columns.Bound<int>(c => c.Id).Width(65).ReadOnly(); columns.Bound<string>(c => c.FirstName).Width(100); columns.Bound<string>(c => c.LastName).Width(100); columns.Bound<string>(c => c.Phone).Width(120); columns.Bound<string>(c => c.Street).Width(200); columns.Bound<string>(c => c.City).Width(100); columns.Bound<string>(c => c.Province).Width(50).Title("Prov"); columns.Bound<string>(c => c.PostalCode).Width(80).Title("PC"); columns.Bound<string>(c => c.Email).Width(100); columns.Bound<bool>(c => c.OkToContact).Width(40).Title("Ok") .ClientTemplate("<input type='checkbox' disabled='disabled' name='OkToContact' <#=OkToContact? checked='checked' : '' #> />"); columns.Command(commands => { commands.Delete(); }).Width(100); }) .DetailView(details => details.ClientTemplate( Html.Telerik().Grid<DonationView>() .Name("Donations_<#= Id #>") .Resizable(resizing => resizing.Columns(true)) .Editable(editing => editing.Mode(GridEditMode.InCell).DefaultDataItem(new DonationView(){Description = "Internal Cause"})) .DataKeys(d => d.Add<int>(a => a.Id).RouteKey("Id")) .Columns(columns => { columns.Bound(o => o.Id).Width(65).ReadOnly(); columns.Bound(o => o.Description).Width(400); columns.Bound(o => o.Amount).Width(80); columns.Bound(o => o.Date).Format("{0:d}"); }) /*.ClientEvents(events => events.OnRowDataBound("cause_onRowDataBound"))*/ .DataBinding(dataBinding => dataBinding.Ajax() .Select("_SelectDonationsHierarchyBatchEditing", "Ajax", new { ContactID = "<#= Id #>" }) .Update("_SaveDonationsHierarchyBatchEditing", "Ajax", new {ContactID = "<#= Id #>"}) ) .Sortable() .ToolBar(commands => { commands.Insert(); commands.SubmitChanges(); }) /*.Filterable()*/ .ToHtmlString() )) .DataBinding(dataBinding => dataBinding.Ajax() .Select("_SelectContactsBatchEditing", "Ajax", new {FirstName = @ViewData["FirstName"], LastName = @ViewData["LastName"]}) .Update("_SaveContactsBatchEditing", "Ajax", new {FirstName = @ViewData["FirstName"], LastName = @ViewData["LastName"]}) ) .Resizable(resizing => resizing.Columns(true)) //.Pageable(paging => paging.PageSize(25)) .Editable(editing => editing.Mode(GridEditMode.InCell)) .DataKeys(d => d.Add<int>(a => a.Id).RouteKey("Id")) .Scrollable(scrolling => scrolling.Height(500)) .ToolBar(commands => { commands.Insert(); commands.SubmitChanges(); }) //.HtmlAttributes(new { style = "width: 1200px" } ) .Sortable() )My `Select()` method calls correctly, however my `Update()` method does not. It simply posts to the same page the grid resides on. I had this working but didn't bother to check in (stupid), and broke it a few days later. No amount of Ctrl+Z has helped me.
Here is the action in my Ajax Controller. Details removed since they don't matter. The method just isn't getting called.
[GridAction] [AcceptVerbs(HttpVerbs.Post)] public ActionResult _SaveContactsBatchEditing([Bind(Prefix = "inserted")]IEnumerable<ContactView> insertedContacts, [Bind(Prefix = "updated")]IEnumerable<ContactView> updatedContacts, [Bind(Prefix = "deleted")]IEnumerable<ContactView> deletedContacts, string FirstName, string LastName) { ISession session = SessionManager.OpenSession(); ContactProvider cp = new ContactProvider(session); if (insertedContacts != null) { //stuff } if (updatedContacts != null) { //stuff } if (deletedContacts != null) { //stuff } IList<ContactView> Contacts = new List<ContactView>(); ContactViewProvider Provider = new ContactViewProvider(SessionManager.OpenSession()); Contacts = Provider.GetContactsByName(FirstName, LastName); //return View(new GridModel(Contacts)); return new LargeJsonResult { MaxJsonLength = int.MaxValue, JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet, Data = new GridModel<ContactView> { Data = Contacts } }; }When I click the Save button in my grid's toolbar, I can use firebug to see the `Select()` method makes the proper AJAX call but the `Update()` method doesn't: (See http://i.stack.imgur.com/GPCS6.png)
In this image the first post url corresponds with the values passed into my `Select()` method. The second post url does not correspond with my `Update()` method.
What's going on here? Thanks in advance