I am using Kendo UI TreeView along with Kendo UI MVC Wrappers in my ASP.NET MVC project.
I have HTML form in my view. Here is the code of my view:
<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>
The tree view is working perfectrly. Here is the code of Categories
action:
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);
}
The problem is that when I click submit
button the form sends all data except the value of the selected CategoryId
.
What is the most elegand way to make the Kendo UI TreeView send CategoryId
when I submit the form?
(If there is no easy way to send it as an input value, I will accept any custom JavaScript code solutions)