Pass data to read action while using virtualization

2 posts, 1 answers
  1. Dave
    Dave avatar
    42 posts
    Member since:
    Jan 2008

    Posted 12 Dec 2018 Link to this post

    How can I pass data from the client to the Read action for a MultiSelect using virtualization. Here is the declaration of the MultiSelect I'm using:

    @(Html.Kendo().MultiSelectFor(model => model.SelectedProjectIds)
        .Filter(FilterType.StartsWith)
        .DataTextField("Name")
        .DataValueField("Id")
        .HtmlAttributes(new { style = "width: 100%" })
        .Placeholder("- Select Project(s) -")
        .DataSource(source =>
        {
            source.Custom()
                .ServerFiltering(true)
                .ServerPaging(true)
                .PageSize(80)
                .Type("aspnetmvc-ajax")
                .Transport(transport =>
                {
                    transport.Read("ProjectRead", "ProjectPlan");
                })
                .Schema(schema =>
                {
                    schema.Data("Data")
                            .Total("Total"); 
                                });
        })
        .Virtual(v => v.ItemHeight(26))
    )

    I'd like to pass in some data in the Transport Read. Here is the action method for the Read:

            [HttpPost]
            public ActionResult ProjectRead([DataSourceRequest] DataSourceRequest request)
            {
                return Json((GetProjects() as List<NamedEntity>).ToDataSourceResult(request));
            }

    So, in addition to the DataSourceRequest object, I'd like to pass in a string from the client-side. How can this be done?

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    683 posts

    Posted 14 Dec 2018 Link to this post

    Hello Dave,

    You could pass additional parameter along with the read request through the Data method:
    .Read(read => read.Action("ProjectRead", "ProjectPlan").Data("additionalData"))
     
    <script>
      function additionalData(e) {
        return {
          myParam: "test"
        }
      }
    </script>

    Then, the additional parameter can be received in a controller method with the following signature:
    public ActionResult ProjectRead([DataSourceRequest] DataSourceRequest request, string myParam) {
      ...
    }

    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