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

Persist Drag and Drop Changes

10 Answers 252 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kyle T.
Top achievements
Rank 1
Kyle T. asked on 19 Apr 2013, 08:04 PM
I apologize up front if there is an obvious answer to this question, but how do I persist the changes that a user makes to the nodes in a tree control when .DragAndDrop(true) is specified?  Since the MVC wrappers using a ReadOnly datasource, I'm really not sure how to do that other than starting to look into doing it outside the MVC wrappers.

Thanks,
Kyle

10 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Apr 2013, 02:20 PM
Hello Kyle,

The Kendo MVC TreeView supports both binding to a model on the server and using remote binding. In order to persist the changes when using drag and drop, you could use the drop event to post the changes to the server and save them or save the current TreeView data when a button is clicked. 

Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kyle T.
Top achievements
Rank 1
answered on 25 Apr 2013, 11:08 PM
Daniel

Thank you for the reply.  I was trying the remote binding but that's where I ran into the DataSource being of type Kendo.Mvc.UI.Fluent.ReadOnlyDataSourceBuilder.  

I'll trying the "binding to a model" approach and let you know if that works.

Thanks,
Kyle
0
Kyle T.
Top achievements
Rank 1
answered on 29 Apr 2013, 07:35 PM
Daniel

I'm still not getting this to work successfully.  I've ended up using a hybrid of the .BindTo to bind to the data and specify the TreeViewItemId that I then use on the client side Drop event to get dropPosition, source TreeViewItemId, and destination TreeViewItemId.  My next step was to code for the various before/after/over dropPosition combinations and call that operation via AJAX until I figured out that after an element has been dropped once it loses it's TreeViewItemId.

Do you have a working example that shows TreeView drag and drop changes being sent back to the server for persisitence? At this point it doesn't matter if it's an MVC wrapper example or not.  

Thanks,
Kyle
0
Kyle T.
Top achievements
Rank 1
answered on 29 Apr 2013, 07:44 PM
Daniel

After finding this response to a similar issue of data lost on drop, http://www.kendoui.com/forums/permalink/SIr9YTAMhEOcpkT3XmrxRQ, I have change how I'm getting the Id's and that is successful now.

So I guess my question is if the path I'm on is really the only way to do this? Or is there a better recommended approach?

Thanks,
Kyle
0
Daniel
Telerik team
answered on 01 May 2013, 08:13 AM
Hello again Kyle,

Indeed, the attributes are currently not persisted and the Id should be found from the node item.
The approach is correct. A custom request should be sent to the server to persist the changes. Also, if the dropPosition is different than "over" then the actual new parent will be the destination item parent. I attached a sample project using the Northwind Employees table.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Laurie
Top achievements
Rank 2
answered on 09 Apr 2015, 09:54 PM

Would it be possible to post an update that's in MVC 5?

Thanks!

Laurie

0
Alex Gyoshev
Telerik team
answered on 13 Apr 2015, 11:27 AM

Hello Laurie,

The relevant code should be identical in MVC5. What problems do you encounter when you use the same view and controller in MVC5?

Regards,
Alex Gyoshev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Laurie
Top achievements
Rank 2
answered on 13 Apr 2015, 03:21 PM

I was actually trying to run the code as is and, after updating the asp.net to 4.5.1 and system.web.mvc to 5, and webpages.version to 3.0.0 in the web.config, I get the following error:

[A]System.Web.WebPages.Razor.Configuration.HostSection <br>cannot be cast to <br>[B]System.Web.WebPages.Razor.Configuration.HostSection. Type A <br>originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, <br>Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context <br>'Default' at location <br>'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.<br> Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0, <br>Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context <br>'Default' at location 'C:\Users\cffmuser\AppData\Local\Temp\Temporary <br>ASP.NET <br>Files\vs\c257a789\13394f7e\assembly\dl3\267cafe6\be4dc955_fc75d001\System.Web.WebPages.Razor.dll'.

I'm able to get the code working in a different project so not a big deal, but it would be helpful if the solution you provide were runnable as is. I'm finding the documentation on the MVC TreeView to be fairly thin.

Thanks.

Laurie

0
Alex Gyoshev
Telerik team
answered on 15 Apr 2015, 06:34 AM

Hello Laurie,

This error can be resolved if you follow the MVC4 to MVC5 upgrade guide, and is not related to the TreeView functionality shown in the project.

Regards,
Alex Gyoshev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Laurie
Top achievements
Rank 2
answered on 15 Apr 2015, 08:47 PM
Got it.  Thanks!
Tags
TreeView
Asked by
Kyle T.
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Kyle T.
Top achievements
Rank 1
Laurie
Top achievements
Rank 2
Alex Gyoshev
Telerik team
Share this question
or