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

Datasource sync after create

1 Answer 157 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Dirk
Top achievements
Rank 1
Dirk asked on 23 Aug 2012, 09:42 AM
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

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 28 Aug 2012, 08:53 AM
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!
Tags
ListView
Asked by
Dirk
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or