【问题标题】:How to get a kendogrid for a kendotreeview selection by using html helper如何使用 html helper 为 kendotreeview 选择获取 kendogrid
【发布时间】:2014-11-10 12:03:34
【问题描述】:

我是这个剑道 ui 框架和 Telerik 文档的新手,我找不到我正在寻找的解决方案。现在我使用 html helper 创建了一个树视图,如下所示,我的要求是如果我选择任何一个节点,我必须在右侧(或任何向下的地方或)获得一个网格,我做对的代码现在如下图所示

@(Html.Kendo().TreeView()
      .Name("treeview") //The name of the treeview is mandatory. It specifies the "id" attribute of the widget.
      .Items(items =>
      {
          items.Add().Text("SystemModelling"); //Add item with text "Item1")
          items.Add().Text("SystemConfiguration") //Add item with text "Item2")
              .Items(it => it.Add().Text("Root"));

          items.Add().Text("Domains"); //Add item with text "Item1")
          items.Add().Text("Roles"); //Add item with text "Item2")
          items.Add().Text("Users"); //Add item with text "Item1")

      })
      .Events(ev=>ev.Select("treeview_select"))
)

<script>
    $(function () {
        // Notice that the Name() of the treeview is used to get its client-side instance
        var treeview = $("#treeview").data("kendoTreeView");
    });
</script>

treeview_select 事件中我需要做什么编码?

编辑

一个简单的疑问,哪个是在 kendo ui 中工作的最佳方式,是使用 Html helper 还是 kendo javascript.IF helper 是一个包装器,那么 helper 和 javascript 之间有什么区别

【问题讨论】:

  • 选择树视图项时使用 Kendo Grid 启动局部视图
  • 一个简单的疑问,哪个是在 kendo ui 中工作的最佳方式,是使用 Html 助手还是 kendo javascript。如果助手是一个包装器,那么助手和 javascript 有什么区别

标签: jquery asp.net-mvc-4 kendo-ui kendo-grid kendo-treeview


【解决方案1】:

您需要在 PartialView 中创建网格,然后在 treeView 中选择节点时读取 id:

  1. 在 treeView (Index.cshtml) 的右侧,您必须创建容器以适应您的网格,例如:

    <div id="GridContainer"></div>
    
  2. 在 PartialView 中,将其命名为例如。 Grid.cshtml 您正在使用 Html.Helper 创建网格,就像在 this kendoGrid demo 中一样。

  3. 在 Controller 中,您声明要像这样读取此 PartialView 的操作:

    public partial class GridController : Controller 
    {
        [HttpPost]
            public PartialViewResult Grid()
            {
                return PartialView();
            }
    }
    
  4. 在 Index.html 中,您可以在 Index.html 中创建 hidden 以确保您的 PartialView URL 正确:

    @Html.Hidden("GridURL", Url.Action("Grid", "Grid"))
    
  5. 您正在创建 JavaScript 函数以使用 ajax() 在 treeView 上读取此网格:

    <script>
        function treeview_select(e){
            $.ajax({
                url: $("#GridURL").val(),
                type: "POST",
                success: function (result) {
                    $("#GridContainer").html(result);
                }
            });
        }
    </script>   
    

【讨论】:

  • 我现在遇到的问题是,我还需要 html 辅助方式的网格,我正在像这样绑定它。这里的网格是基于我不想要的 javascript 生成的
  • 我想我误解了你的问题。我完全更新了我的答案。
  • 一个简单的疑问,哪个是在 kendo ui 中工作的最佳方式,是使用 Html 助手还是 kendo javascript。如果助手是一个包装器,那么助手和 javascript 有什么区别
  • 这是一个非常好的问题。 Html 助手只是生成 javascript 代码并将其粘贴到查看。如果你熟悉 C# 而不是 JS 会很方便。第二个优点是 C# 的 IntelliSense 稍微好一点。现在的缺点:C# 没有 JavaScript 包装器所具有的所有功能。在事件处理中你无法避免 JS - 你必须用 JavaScript 编写它。而且带有 C# 的剑道更贵(我上次检查时为 699 美元 JS/999 美元 MVC)。
猜你喜欢
  • 2011-06-15
  • 1970-01-01
  • 2011-01-23
  • 2010-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-24
相关资源
最近更新 更多