Kendo ui 使用KendoUI树视图作为输入值

Kendo ui 使用KendoUI树视图作为输入值,kendo-ui,kendo-asp.net-mvc,kendo-treeview,Kendo Ui,Kendo Asp.net Mvc,Kendo Treeview,我在ASP.NET MVC项目中与剑道UI MVC包装器一起使用 我的视图中有HTML表单。以下是我的视图的代码: <form method="POST" action="@Url.Action("Review")"> @* ... *@ @(Html.Kendo().TreeView() .Name("CategoryId") .DataTextField("Name") .DataSource(dataSource

我在ASP.NET MVC项目中与剑道UI MVC包装器一起使用

我的视图中有HTML表单。以下是我的视图的代码:

<form method="POST" action="@Url.Action("Review")">
    @* ... *@
    @(Html.Kendo().TreeView()
        .Name("CategoryId")
        .DataTextField("Name")
        .DataSource(dataSource => dataSource
            .Read(read => read.Action("Categories", "ReviewCategories"))
        )
    )
    @* ... *@
    <input type="submit" class="btn btn-primary" value="Submit" />
</form>
public JsonResult Categories(int? id)
{
    var categories = this.forumCategoriesService.All()
       .Where(x => id.HasValue ? x.ParentId == id : x.ParentId == null)
       .Select(x => new { id = x.Id, Name = x.Title, hasChildren = x.Children.Any() });

    return this.Json(categories, JsonRequestBehavior.AllowGet);
}
问题是当我单击
提交
按钮时,表单会发送除所选
类别ID的值以外的所有数据

当我提交表单时,让Kendo UI TreeView发送
类别ID
的最简单的方法是什么


(如果没有简单的方法将其作为输入值发送,我将接受任何自定义JavaScript代码解决方案)

我找到了一个解决方法

首先:使用所需参数创建隐藏输入:

<input type="hidden" name="CategoryId" id="CategoryId" value="@Model.CategoryId" />
Third:实现处理程序并更改其中
#CategoryId
的值

function onCategorySelect(ev) {
    var dataItem = this.dataItem(ev.node);
    var categoryId = dataItem.id;
    $("#CategoryId").val(categoryId);
}
如果有人知道更好的解决方案,欢迎添加其他答案

function onCategorySelect(ev) {
    var dataItem = this.dataItem(ev.node);
    var categoryId = dataItem.id;
    $("#CategoryId").val(categoryId);
}