如何制作ajax更新面板? (MVC2)
我正在使用 Telerik 树视图控件:
- http://demos.telerik.com/aspnet-mvc/treeview
- http://demos.telerik.com/aspnet-mvc/treeview/clientsideevents
我想要做的是在左侧设置此控件,然后在右侧设置一个“面板”,即单击树视图时更新的视图。
因此,我想在树视图中单击时进行 AJAX 调用以从数据库检索信息。然后我可以使用当前项目的信息更新“面板”。
我该如何构建这个“面板”?任何为 ASP.NET MVC2 设计的控件都更好,因为这就是我实现的。我看到了一个名为 UFRAME 的东西,但它让我想起了 IFRAME,并认为我应该避免使用它。
我可以使用部分视图来执行此操作,然后仅更新页面的部分视图区域吗?
谢谢。
I am using Telerik tree view control:
- http://demos.telerik.com/aspnet-mvc/treeview
- http://demos.telerik.com/aspnet-mvc/treeview/clientsideevents
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. 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.
Can I do this with a partial view, and then just the partial view area of the page updates ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Telerik
TreeView
有:OnSelect
客户端事件,这就是要开发的过程。
我一生中从未使用过 Telerik 的控件,但根据其页面上的文档,它似乎是这样工作的。除了您必须使用的
OnSelect
客户端事件之外,一切基本上都是常见的 Asp.net MVC + jQuery。因此,只要 Telerik 的控件按预期工作(这可能是一个独立的故事),就没有什么特别复杂的事情。一些代码
由于我从未使用过 Telerik,我仍然认为这可以沿着线完成一些事情:
你在你的视图之一中定义了 TreeView,例如:
然后使用 jQuery 完成其余操作:
<前><代码>$(函数(){
$("#ClientSideID").bind("选择", 函数(e){
e.preventDefault();
$.ajax({
url: "一些URL",
数据:e.item,
类型:“帖子”,
成功:函数(partialView){
部分视图 = $(部分视图);
$("RightPanelSelector").append(partialView);
},
错误:函数(xhr,状态,错误){
// 处理错误
}
});
});
});
此代码未经测试,但可以帮助您入门。
Telerik
TreeView
has:OnSelect
client side event thatPartialView
whichThat'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. Everything is basically the usual Asp.net MVC + jQuery except for the
OnSelect
client side event that you have to use. So nothing particularly complicated as long as Telerik's controls work as expected (which can be a story of its own).Some code
Since I've never used Telerik, I still think this can be done something along the line:
You have your TreeView defined in one of your views like:
Then use jQuery to do the rest:
This code isn't tested but will get you started.