# Persist Drag and Drop Changes

1. ##### Kyle T.
16 posts
Member since:
Dec 2011

Posted 19 Apr 2013 Link to this post

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
2. ##### Daniel
2125 posts

Posted 23 Apr 2013 Link to this post

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
3. ##### Kyle T.
16 posts
Member since:
Dec 2011

Posted 25 Apr 2013 Link to this post

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
4. ##### Kyle T.
16 posts
Member since:
Dec 2011

Posted 29 Apr 2013 Link to this post

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
5. ##### Kyle T.
16 posts
Member since:
Dec 2011

Posted 29 Apr 2013 Link to this post

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
6. ##### Daniel
2125 posts

Posted 01 May 2013 Link to this post

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
7. ##### Laurie
144 posts
Member since:
Feb 2007

Posted 09 Apr 2015 Link to this post

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

Thanks!

Laurie

8. ##### Alex Gyoshev
2508 posts

Posted 13 Apr 2015 Link to this post

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.

9. ##### Laurie
144 posts
Member since:
Feb 2007

Posted 13 Apr 2015 in reply to Alex Gyoshev Link to this post

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

10. ##### Alex Gyoshev
2508 posts

Posted 15 Apr 2015 Link to this post

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.

11. ##### Laurie
144 posts
Member since:
Feb 2007

Posted 15 Apr 2015 in reply to Alex Gyoshev Link to this post

Got it.  Thanks!