2010-02-15 77 views
1

这里的问题:与ASP.NET MVC的jQuery TreeView如何传递参数到URL

我想与异步执行一个Active Directory资源管理器。 jQuery TreeView。在标准的ASP.NEt中,使用内置的TreeView和一些代码隐藏事件很容易。

问题是,我不完全知道如何传递不同的参数,具体取决于正在展开哪个treeview叶。基于这个例子http://view.jquery.com/trunk/plugins/treeview/demo/async.html我可以看到,如果使用PHP,并且在页面加载时传递'root'参数,那么这是非常简单的。

例如,

我有这样的树:

+ A
+ B
+ C

,我想打电话给myController的/ MyAction/B时扩大B.我应该在

添加一些方法
<script type="text/javascript"> 
    $(document).ready(function(){ 
     $("#black").treeview({ 
      url: "source.php" 
         toggle: do_something_here? 
     }) 
    }); 
    </script> 

我有点卡在这里,所以任何帮助将不胜感激。

回答

0

正如yoiu可以看到,如果你使用Firebug与示范,扩大节点触发对数据的GET要求:

http://view.jquery.com/trunk/plugins/treeview/demo/source.php?root=36

的反应仅仅是JSON:

[ 
    { 
     "text": "1. Review of existing structures", 
     "expanded": true, 
     "children": 
     [ 
      { 
       "text": "1.1 jQuery core" 
      }, 
      { 
       "text": "1.2 metaplugins" 
      } 
     ] 
    }, 
    { 
     "text": "2. Wrapper plugins" 
    }, 
    { 
     "text": "3. Summary" 
    }, 
    { 
     "text": "4. Questions and answers" 
    } 

] 

所以你可以编写MVC动作(不要在URI中使用.php!):

public JsonResult Source(string root) 
{ 
    var model = new object[] 
     { 
      new 
      { 
       text = "1. Review of existing structures", 
       expanded = true, 
       children = new object[] 
       { 
        new 
        { 
         text = "1.1 jQuery core", 
        }, 
        new 
        { 
         text = "1.2 metaplugins" 
        } 
       } 
      }, 
      new 
      { 
       text = "2. Wrapper plugins" 
      }, 
      new 
      { 
       text = "3. Summary" 
      }, 
      new 
      { 
       text = "4. Questions and answers" 
      } 
     }; 
    return Json(model); 
} 

从这里,应该很明显如何根据根参数进行切换。

+0

Yhm,我知道我可以如何在我的控制器中进行后端处理。事情是我不知道如何通过你所说的“根参数”。我如何让参数传递给我的动作取决于哪个树叶展开。我如何在View with JavaScript/jQuery中执行此操作。 – anusiak 2010-02-15 18:00:37

+0

我的意思是36怎么得到int这个请求。有没有办法在那里包含一些不是数字的价值? – anusiak 2010-02-15 18:11:18

+0

啊,好的,我找到了:)非常感谢您的回答;-) – anusiak 2010-02-15 18:39:02