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

Pass data to read action while using virtualization

1 Answer 285 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 12 Dec 2018, 03:16 PM

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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 14 Dec 2018, 08:22 AM
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.

Tags
MultiSelect
Asked by
Dave
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or