This question is locked. New answers and comments are not allowed.
Hi,
Have an Ajax bound grid in a partial view that renders fine and can be paged, sorted and filtered successfully using Ajax binding.
When I try and implement Delete and Insert functionality, the controller actions are not called. Instead the original HTTP Get action is called.
Using 2010.2.825
Partial View...
Controller...
View that hosts the partial view...
When I click on the Insert or Delete buttons, the HTTP Get List action is called instead of the Ajax action methods.
I have ensured I'm using v1.7 of the jquery validate library (as per a previous post that seemed related).
Any ideas?
Thanks,
Alastair
Have an Ajax bound grid in a partial view that renders fine and can be paged, sorted and filtered successfully using Ajax binding.
When I try and implement Delete and Insert functionality, the controller actions are not called. Instead the original HTTP Get action is called.
Using 2010.2.825
Partial View...
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ArtifactListViewModel>" %> <% Html.Telerik().Grid(Model.Artifacts) .Name("ArtifactsGrid") .HtmlAttributes(new { style = "margin-top: 15px; margin-bottom: 15px;" }) .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0" })) .DataKeys(keys => keys.Add(k => k.ArtifactId)) .DataBinding(dataBinding => dataBinding .Ajax() .Select("List_TelerikAjaxBinding", "Artifact", new { matrixRecordId = Model.MatrixRecordId }) .Delete("Delete_TelerikAjaxBinding", "Artifact") .Insert("Add_TelerikAjaxBinding", "Artifact") ) .Columns(columns => { columns.Command(commands => { commands.Delete().ButtonType(GridButtonType.Text); }).Width(100); columns.Bound(o => o.Hyperlink).Encoded(false).Filterable(false).Sortable(false).Title("").Width(30); columns.Bound(o => o.ArtifactType).Title("Type").Width(260); columns.Bound(o => o.ArtifactStatus).Title("Status").Width(100); columns.Bound(o => o.ReceiptDate).Title("Receipt Date/Time").Format("{0:dd/MM/yy HH:mm}").Width(180); columns.Bound(o => o.Author).Title("Author").Width(200); columns.Bound(o => o.VersionNumber).Title("Version").Width(80); columns.Bound(o => o.TargetCompletionDate).Title("Target Completion Date").Format("{0:dd/MM/yy}").Width(180); columns.Bound(o => o.ActualCompletionDate).Title("Actual Completion Date").Format("{0:dd/MM/yy}").Width(180); }) .Editable(editing => editing.Enabled(true).Mode(GridEditMode.PopUp).DisplayDeleteConfirmation(true)) .Scrollable() .Resizable(resizing => resizing.Columns(true)) .Sortable(sorting => sorting .OrderBy(sortOrder => sortOrder.Add(o => o.ReceiptDate).Descending())) .Filterable() .Pageable(paging => paging.PageSize(20)) .Render(); %> Controller...
// // GET: /Artifact/List/1 public ActionResult List(int matrixRecordId) { return PartialView(this._List(matrixRecordId)); }
// Used for the Ajax binding from Telerik Grid (sorting, paging, filtering requests) [GridAction] public ActionResult List_TelerikAjaxBinding(int matrixRecordId) { return View(new GridModel() { Data = this._List(matrixRecordId).Artifacts }); }
/// <summary> /// Setup the ViewModel with the queryable list of Artifacts /// </summary> /// <param name="matrixRecordId"></param> /// <returns></returns> private ArtifactListViewModel _List(int matrixRecordId) { // create the View Model ArtifactListViewModel model = new ArtifactListViewModel();
// want to retrieve meaningful data for related properties so specify the properties to eager load string[] propertiesToEagerLoad = new string[] { "ArtifactType", "ArtifactStatus", "Author" }; IEnumerable<Artifact> artifacts = this._artifactRepository.List( propertiesToEagerLoad, where => where.MatrixRecord.MatrixRecordId == matrixRecordId); List<ArtifactListAtrifact> modelArtifacts = new List<ArtifactListAtrifact>(); foreach (Artifact artifact in artifacts) { modelArtifacts.Add(new ArtifactListAtrifact() { ArtifactId = artifact.ArtifactId, ArtifactStatus = artifact.ArtifactStatus.ShortName, ArtifactType = artifact.ArtifactType.ShortName, Author = string.Format("{0} {1}", artifact.Author.FirstName.Trim(), artifact.Author.Surname.Trim()).Trim(), ReceiptDate = artifact.ReceiptDate, VersionNumber = artifact.VersionNumber, Hyperlink = this.GetIconForHyperlink(artifact.Hyperlink), TargetCompletionDate = artifact.TargetCompletionDate, ActualCompletionDate = artifact.ActualCompletionDate }); } model.Artifacts = modelArtifacts; model.MatrixRecordId = matrixRecordId; model.IsGeneralUser = Roles.IsUserInRole(RoleNames.GeneralUser); model.IsAuthorisedUser = Roles.IsUserInRole(RoleNames.AuthorisedUser); model.IsSuperUser = Roles.IsUserInRole(RoleNames.SuperUser);
return model; }
[HttpPost] [GridAction] public ActionResult Delete_TelerikAjaxBinding(int id) { this._artifactRepository.DeleteById(id);
// rebind the grid return View(new GridModel() { Data = this._List(52).Artifacts }); }
[HttpPost] [GridAction] public ActionResult Add_TelerikAjaxBinding() { Artifact artifact = new Artifact();
//Perform model binding (fill the product properties and validate it). if (TryUpdateModel(artifact)) { this._artifactRepository.Add(artifact); }
// rebind the grid return View(new GridModel() { Data = this._List(52).Artifacts }); } View that hosts the partial view...
<%--this view hosts partial views loaded by AJAX. Telerik scripts used within these partials must be manually loaded (in the right order) in the containing view (i.e. here) --%> <% Html.Telerik().ScriptRegistrar().DefaultGroup(group => group .Add("telerik.common.min.js") .Add("telerik.calendar.min.js") .Add("telerik.datepicker.min.js") .Add("telerik.textbox.min.js") .Add("telerik.grid.min.js") .Add("telerik.draganddrop.min.js") .Add("telerik.grid.grouping.min.js") .Add("telerik.grid.filtering.min.js") .Add("telerik.grid.resizing.min.js") .Add("telerik.grid.editing.min.js") .Add("telerik.window.min.js") ); %> </asp:Content>When I click on the Insert or Delete buttons, the HTTP Get List action is called instead of the Ajax action methods.
I have ensured I'm using v1.7 of the jquery validate library (as per a previous post that seemed related).
Any ideas?
Thanks,
Alastair