treeview Passing Additional Data Server Call

2 posts, 0 answers
  1. Angela
    Angela avatar
    1 posts
    Member since:
    Aug 2018

    Posted 25 Apr Link to this post

    Hi I am struggling to figure this out...I am trying to pass additional data on the call.  The id that treeview comes up with is always there and correct.  But my roleid is always null.  And the RoleId is valid number.  Running out of places to look so I figured I post...

     

    @(Html.Kendo().TreeView()
                                    .Name("permissionList")
                                    .Checkboxes(true)
                                    .DataTextField("name")
                                    .DataSource(dataSource => dataSource
                                        .Read(read => read.Action("permissions", "roles", new { RoleId = @Model.RoleId}))
                                    )
                        )

     

    Controller

            [HttpGet]
            [Route("permissions")]
            [Route("permissions/{id}/{RoleId}")]
            public JsonResult Permissions(int? id, int? RoleId)
            {
                var roleFormMgr = new RoleFormMgr(StateMgmt);
                var roleEntity = roleFormMgr.GetRole(RoleId.GetValueOrDefault());
                var roleFormVM = roleFormMgr.PopulateView(Mapper.Map<RoleForm>(roleEntity));
                var permissions = roleFormVM.RolePermissionList.Where(p => id.HasValue ? p.parentId == id : (id == null && p.parentId == 0)).ToList();
                return Json(permissions, JsonRequestBehavior.AllowGet);
            }

  2. Dimitar
    Admin
    Dimitar avatar
    685 posts

    Posted 29 Apr Link to this post

    Hi Angela,

    The Data() method could be used to pass additional data to the controller end-point as follows:
    @(Html.Kendo().TreeView()
      ...
      .DataSource(dataSource => dataSource
        .Read(read => read
          .Action("Read_TreeViewData", "Home").Data("onAdditionalData")
        )      
      )
    )
     
    <script>
       var role = @Html.Raw(Json.Encode(Model.RoleId));
     
        function onAdditionalData(e) {
            return {
                roleId: role
            }
        }
    </script>

    Then, the data can be successfully received in the controller end-point:
    public ActionResult Read_TreeViewData(int? id, int roleId)
    {
      ...
    }


    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top