简体   繁体   English

如何制作ajax更新面板? (MVC2)

[英]How to make ajax update panel ? (MVC2)

I am using Telerik tree view control: 我正在使用Telerik树视图控件:

What I want to do is set up this control on the left, then a "panel" on the right, that is a view that updates when the treeview is clicked. 我想要做的是在左侧设置此控件,然后在右侧设置“面板”,即在单击树视图时更新的视图。

So I want to do AJAX call to retrieve info from DB when a click is made in the tree view. 因此,当在树视图中单击时,我想进行AJAX调用以从数据库检索信息。 Then I can update the "panel" with information on the current item. 然后我可以用当前项目的信息更新“面板”。

How could I go about building this "panel" ? 我怎么能建立这个“小组”? And any controls that are designed for ASP.NET MVC2 are better as that is what I am implementing this in. I saw something called UFRAME but it reminded me of IFRAME and thought I should probably avoid it. 并且为ASP.NET MVC2设计的任何控件都更好,因为我正在实现它。我看到了一个名为UFRAME的东西,但它让我想起了IFRAME,并认为我应该避免它。

Can I do this with a partial view, and then just the partial view area of the page updates ? 我可以使用局部视图执行此操作,然后只更新页面的部分视图区域吗?

Thanks. 谢谢。

Telerik TreeView has: Telerik TreeView具有:

  1. OnSelect client side event that OnSelect客户端事件
  2. you want to subscribe to and 您要订阅和
  3. issue an Ajax call when select happens 选择发生时发出Ajax调用
  4. to your Asp.net MVC application controller action that 到您的Asp.net MVC应用程序控制器操作
  5. would return a PartialView which 将返回一个PartialView
  6. you can then append to right panel 然后可以附加到右侧面板

That's the process to be developed. 这就是要开发的过程。

I've never used Telerik's controls in my life but based on the documentation on their page it seems that it works this way. 我一生中从未使用过Telerik的控件,但是根据其页面上的文档,似乎它可以这种方式工作。 Everything is basically the usual Asp.net MVC + jQuery except for the OnSelect client side event that you have to use. 一切都基本上是通常的Asp.net MVC + jQuery,除了你必须使用的OnSelect客户端事件。 So nothing particularly complicated as long as Telerik's controls work as expected (which can be a story of its own). 因此,只要Telerik的控件能够按预期工作(这可能是一个故事),就没有什么特别复杂的事情。

Some code 一些代码

Since I've never used Telerik, I still think this can be done something along the line: 由于我从未使用过Telerik,因此我仍然认为可以做到这一点:

  1. You have your TreeView defined in one of your views like: 您在其中一个视图中定义了TreeView,例如:

     <%= Html.Telerik().TreeView().Name("ClientSideID") %> 
  2. Then use jQuery to do the rest: 然后使用jQuery完成其余工作:

     $(function(){ $("#ClientSideID").bind("select", function(e){ e.preventDefault(); $.ajax({ url: "SomeURL", data: e.item, type: "POST", success: function(partialView) { partialView = $(partialView); $("RightPanelSelector").append(partialView); }, error: function(xhr, status, err){ // handle error } }); }); }); 

This code isn't tested but will get you started. 此代码未经过测试,但可以帮助您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM