Datasource sync after create

2 posts, 0 answers
  1. Dirk
    Dirk avatar
    1 posts
    Member since:
    Aug 2012

    Posted 23 Aug 2012 Link to this post

    Hi

    I have a simple razor page using the Listview

       @(Html.Kendo().ListView<MVCTicketSystem.ViewModels.TicketDetail>(Model)
              .Name("listView")
              .TagName("div")
              .ClientTemplateId("list-view-template")          
              .DataSource(dataSource => dataSource
                                            .Model(model => model.Id("TicketEntryId"))                                        
                                            .PageSize(5)                                        
                                            .Create(create => create.Action("TicketDetail_Create", "Ticket").Data("TicketInfo"))
                                            .Read(read => read.Action("TicketDetail_Read", "Ticket").Data("TicketInfo"))
                                            .Update(update => update.Action("TicketDetail_Update", "Ticket"))
                                            .Destroy(destroy => destroy.Action("TicketDetail_Destroy", "Ticket"))                                        
                                            .Sort(f=>f.Add(p=>p.DetailDate).Descending())                                                                                                        
              )
              .Pageable()          
              .Editable())

    The Create method works but the object is partially populated at the server side and I need to visualize this data when the object is added to the list. So I need to either trigger a refresh of the current page or of the added object or something simular after the create.

    I've searched the forum but can't find an answer to this problem which is strange as I guess everyone needs this kind of behavior.

    best regards
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 28 Aug 2012 Link to this post

    Hi Dirk,

    Basically if you return the newly created item as shown in our offline demos you should get the values updated back on the client.
    Here is how the Create action method looks like:
    [AcceptVerbs(HttpVerbs.Post)]
           public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
           {
               var results = new List<ProductViewModel>();
     
               if (product != null && ModelState.IsValid)
               {               
                   SessionProductRepository.Insert(product);
                   results.Add(product);               
               }
     
               return Json(results.ToDataSourceResult(request, ModelState));
           }


    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
Back to Top