ASP.NET MVC 3树形 [英] ASP.NET MVC 3 Treeview

查看:306
本文介绍了ASP.NET MVC 3树形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示在我MVC3应用程序中的树视图。会有一个自参考分层表(文件夹),并链接到它的另一表(文件)(因此夹可具有N-二子和任何文件夹/子文件夹可以有许多文件。)

I need to display a Treeview in my MVC3 application. There will be a self referencing hierarchical table (Folders) and another table linked to it (Documents.) (So Folders can have N-subFolders and any folder/sub folder can have many documents.)

我已经调查使用第三方厂商如Telerik的,DJME和MVC控制工具包。虽然所有漂亮的包,我不安的许可,因为我是新来的MVC(和编程一般,)我觉得他们缺少的文件以获得正确的显示工作。

I have looked into using third party vendors such as Telerik, DJME and MVC Controls Toolkit. While all nice packages, I'm uneasy about the licences, and since i'm new to MVC (and programming in general,) I find their documentation lacking to get the right display working.

我也看了大量引用博客上的TreeView:

I've also looked at the heavily referenced blogs on TreeViews:

<一个href=\"http://www.matthidinger.com/archive/2009/02/08/asp.net-mvc-recursive-treeview-helper.aspx\">TreeViewHelper
和<一个href=\"http://weblogs.asp.net/mikebosch/archive/2008/11/25/hierarchical-treeview-with-asp-net-mvc-jquery.aspx\">Recursive局部视图

除了其他不太引用的文章(前3名也非常丰富):

In addition to the other less referenced articles (The top 3 are also very informative):


  1. http://tpeczek.blogspot.com/2010/01/asynchronous-treeview-in-aspnet-mvc.html

  2. http://mikehadlow.blogspot.com/2008/10/rendering-tree-view-using-mvc-framework.html

  3. http://www.tek-tips.com/viewthread.cfm?qid=1637392&page=4

  4. http://weblogs.asp.net/jigardesai/archive/2008/02/04/display-hierarchical-data-in-asp-net-mvc-framework.aspx

  5. http://www.jigar.net/articles/viewhtmlcontent311.aspx

  6. http://help.syncfusion.com/ug_82/ASP.NETMVCUI_Tools/CreatingATreeViewControl.html

我想请使用TreeViewHelper或递归局部视图的方法。结果
然而,在TreeViewHelper,我不能让它从第二个表中取出数据(即我只能让它列表中的文件,但我不知道如何把它列出文件为每个文件。)

对于递归局部视图,我仍然在如何将其转换为MVC3及一般执行的损失。我确实发现提供了如何有点转换它来MVC3的解释后(forums.asp.net/t/1652809.aspx/1?treeview+with+mvc+3),但我仍然不清楚如何处理它。我不断收到错误的局部视图:不能隐式转换类型'无效'输入'对象'

I would like to use either the TreeViewHelper or the Recursive Partial View Method.
However, in the TreeViewHelper, I can't make it pull data from the second table (ie. I can only make it list the Files, but I'm not sure how to have it list the Documents for each File.)
For the Recursive Partial View, I'm still at a loss in how to convert this to MVC3 and also general implementation. I did find a post (forums.asp.net/t/1652809.aspx/1?treeview+with+mvc+3) that gives an explanation of how to convert a bit of it to MVC3, but i'm still unclear of what to do with it. I keep getting the error for the Partial view: Cannot implicitly Convert type 'void' to type 'object'

就像我之前说我是新来MVC3,并想深入了解其中的方法将工作最适合我的情况和如何实现它。

Like I said before I'm new to MVC3 and would like insight in which method would work best for my scenario and how to implement it.

推荐答案

在情况下,你想知道,我解决了这个问题的方法是使用递归局部视图。我曾与它遇到的问题是,我没有自我引用关系SQL / EF成立了(我只是这是不链接到主键PARENTID场)。我还集成jsTree,因为这有一个很多华而不实的功能,如搜索。

In case anyone is wondering, the way I solved this problem was to use a recursive partial view. The problem I has having with it was that I didn't have the self referencing relationship set up in SQL/EF (I just had the ParentID field which wasn't linked to the Primary Key.) I also integrated jsTree as this has a lot of slick functionality such as search.

就像我上面,@ Html.Action和@ Html.Partial工作,而不是@ Html.RenderAction和@ Html.RenderPartial。

Like I said in the comment above, @Html.Action and @Html.Partial work instead of @Html.RenderAction and @Html.RenderPartial.

这篇关于ASP.NET MVC 3树形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆