2017-04-20 65 views
0

我有这个任务需要在html中构建父/子视图。不使用任何插件!ASP.NET MVC构建子/父树

我已经在子节点的控制器中创建了一个数据库和一个模型(H_Table)以及一个类(Element)。 但是,我如何得到这个一起工作。因此,它从模型中检索数据将其传递给类并返回查看模型。我不确定我是否正确地解释它。询问。

我的模型:

namespace Tree_List.Models 

{ 
    using System; 
    using System.Collections.Generic; 

    public partial class H_Table 
    { 
     public int ID { get; set; } 
     public string NAME { get; set; } 
     public Nullable<int> PARENT_ID { get; set; } 
    } 

} 

我的控制器:

using System.Collections.Generic; 
using System.Web.Mvc; 
using Tree_List.Models; 

namespace Tree_List.Controllers 
{ 
    public class ListController : Controller 
    { 
     // GET: List 
     private Models.ListDBEntities1 db_connection = new Models.ListDBEntities1(); 

     public ActionResult Index() 
     { 
      var Items = db_connection.H_Table; 

      return View(Items); 
     } 
    } 

    public partial class Element 
    { 
     public int ID { get; set; } 
     public string NAME { get; set; } 
     public List<Element> CHILDS { get; set; } 

    } 
} 
+0

与数据表去,https://datatables.net/examples/api/row_details.html。 – Bharat

+0

@Bharat我很少使用插件!用于数据表的 – SonOfAGun

+0

,你只需要js文件,没有别的。它很容易使用.. – Bharat

回答

0

如果我得到你的问题的权利,你要呈现在视图中你这个层次数据。要做到这一点,你必须使用JavaScript和jQuery呈现此数据有关于如何做到这一点像吨准备库和开源的例子:

https://www.codeproject.com/tips/696985/how-to-create-treeview-in-mvc

https://www.mindstick.com/Articles/1119/using-treeview-in-asp-dot-net-mvc

你可以看到他们,自己写一个像他们一样。另外请看Telerik更抽象的工具。

希望它能帮助:)