This is a migrated thread and some comments may be shown as answers.

treeview Passing Additional Data Server Call

1 Answer 426 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Angela
Top achievements
Rank 1
Angela asked on 26 Apr 2019, 12:51 AM

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);
        }

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 29 Apr 2019, 07:54 AM
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.
Tags
TreeView
Asked by
Angela
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or