This is a migrated thread and some comments may be shown as answers.

[Solved] Binding problem after ajax editing

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stefan
Top achievements
Rank 1
Stefan asked on 28 Oct 2011, 10:05 AM
Hi,

I want to use the Grid with Ajax binding. Initially the grid is diplayed correctly. When updating, the Action method is called, but when I return the updated GridModel the Grid seems to bind the rows, but all columns are empty. What I am doing wrong ?

Grid in View:
Html.Telerik().Grid(Model)
        .Name("Grid")  
        .DataKeys(keys => { keys.Add( g => g.Id ); })
        .Columns(columns =>
            {
                columns.Template(@<text>
                                    <a href="@Url.Action("Up", new { GalleryId = @item.GalleryId, ImageId = @item.Id })"><img src="@Url.Content("~/Content/Images/active.png")" alt="Nach oben"/></a>
                                    <a href="@Url.Action("Down", new { GalleryId = @item.GalleryId, ImageId = @item.Id })"><img src="@Url.Content("~/Content/Images/inactive.png")" alt="Nach oben"/></a>
                                 </text>).Width(40);               
                columns.Template(@<text>
                                    <img alt='@item.FilePath' src='@item.FilePath?width=200&height=200' style= 'vertical-align:middle;'/>
                                 </text>)
                    .HeaderTemplate(@<text><input type="image" src="@Url.Content("~/Content/Images/add.png")" alt="Bild" onclick="openDialog();return false;"/></text>)
                    .Width(210);
 
                columns.Template(@<text><h3>@item.Title</h3><p>@item.Description</p></text>).Title("Titel / Beschreibung");
                columns.Command(commands =>
                {
                    commands.Edit().ButtonType(GridButtonType.Image);
                });          
            })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_CustomBinding", "Gallery", new { id = @ViewBag.AlbumId } )
                                                      .Update("_SaveGalleryItem", "Gallery" ))                                                
        .Editable(editing => editing.Mode(GridEditMode.PopUp))                                                     
        .Sortable(sorting => sorting.OrderBy( sortOrder => sortOrder.Add( o => o.SortNr ).Ascending() ) )
        .Render();

Initial Action for filling Grid:

public ActionResult EditGallery(Guid id)
{
  var lstImages = PrepareForImageView(id, _galleryRepository.ListImages(id));
 
            return View(lstImages);
}

Action for Ajax Edit:
[AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveGalleryItem(FormCollection collection)
        {
            Guid id = new Guid(collection["id"]);
            var image = _galleryRepository.GetImage(id);
 
            image.Title = collection["Title"] == null ? string.Empty : collection["Title"].ToString();
            image.Description = collection["Description"] == null ? string.Empty : collection["Description"].ToString();
 
            _galleryRepository.SaveChanges();
 
            var lstImages = PrepareForImageView(image.GalleryId, _galleryRepository.ListImages(image.GalleryId));
 
            return View(new GridModel(lstImages));           
        }

1 Answer, 1 is accepted

Sort by
0
Stefan
Top achievements
Rank 1
answered on 28 Oct 2011, 11:58 AM
Hi,

I made a mistake. I used the grid before in server binding mode and now that i changed it to ajax binding, I did not adapt the grid for that mode correctly. ( Instead of template --> client template, Grid(model) --> Grid<Type>(), .... )

Sorry for any inconvenience
Tags
Grid
Asked by
Stefan
Top achievements
Rank 1
Answers by
Stefan
Top achievements
Rank 1
Share this question
or