从存储过程中加载的C#Mvc3中的TreeViews [英] TreeViews in C# Mvc3 Loaded from a stored procedure

查看:106
本文介绍了从存储过程中加载的C#Mvc3中的TreeViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我在为正在处理的项目中添加树形视图时遇到很多麻烦,需要一些建议

我有一个局部视图,应该从此存储过程中加载类别列表.

Hey All,
I''m having a lot of trouble adding a tree view to a project I''m working on and need some advise

I have a partial view that is supposed to load a list of categories from this stored procedure

List<spTestResult> CategoryList = DB.spTest().ToList();


返回的结果内部是带有这些ID的表:


Inside the returned result is a table with these Ids:

CategoryID, CategoryName, CategoryParentID



如果一个文件夹的CategoryParentID等于另一个文件夹的CategoryID,则它应该成为树视图上的子文件夹.

我对MVC完全陌生,我发现所有示例链接都对树视图中的值进行了硬编码,因此我不知道如何在显示数据和使用我先前返回的存储过程列表之间添加链接. br/> 我以为我会使用Jquery UI,但是我发现的示例也对所有值进行了硬编码.

有人可以给我一些有关它应该如何工作的指示吗?我已经在Webforms上做了很多次树视图,但是在Mvc上,我们似乎一开始就没有树视图控件.

在此先感谢您,如果您需要更多代码,或者我想随意告诉我,我不确定我是否完全解决了这个问题



If the CategoryParentID of a folder is equal to the CategoryID of another its supposed to become its child on the treeview.

I''m completely new to MVC and all of the example links i''ve found Hardcode the values inside the treeview so I have no idea how to add the link between displaying the data and using that stored procedure list I returned earlier.
I imagined I would be using Jquery UI but the examples I found also hard coded all the values.

Can someone give me some pointers on how its supposed to work? I''ve made a treeview on webforms plenty of times but on Mvc we don''t seem to have a treeview control to use in the first place.

Thanks in advance, If you need any more code or I missed anything feel free to tell me, I''m not sure if I covered the issue fully

推荐答案

一次您已将数据从数据库作为平面表返回,则需要根据关键字列对数据进行分组.您可以使用 CollectionView [ LINQ分组依据 [
Once you have your data returned from DB as flat table you need to group it based on your key columns. You coul use either CollectionView[^] implementation class or LINQ Group By[^] feature.
For more information see respective links.


http://www.matthidinger.com/archive/2011/11/27/Writing-a-Fluent-ASP-NET-MVC-Recursive-TreeView-Helper.aspx[^]

I used the source code on that blogs project site


这篇关于从存储过程中加载的C#Mvc3中的TreeViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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