Home > Mobile >  Kendo UI passing control value to DataSource
Kendo UI passing control value to DataSource

Time:06-04

Hi I have a fairly simple MultiSelect dropdown with the following Datasource

@(Html.Kendo().MultiSelectFor(model => model.UserId)
    .Name("UserId")
    .HtmlAttributes(new { style = "width:100%;" })
    .MinLength(2)
    .Filter(FilterType.Contains)
    .Placeholder("Select User...")
    .AutoBind(false)
    .Animation(false)
    .MaxSelectedItems(1)
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetUsers", "CommonJsonActions");
        });
    })
    .DataValueField("UserId")
    .DataTextField("DisplayName")
    .BindTo(Model.Users)
    .Value(Model.Users)

I'm wondering if there's a way I can pass the selected value of another dropdown, say id formType, to the MultiSelect? Or do I must move the code to .js file to utilize jquery for this purpose?

CodePudding user response:

To pass additional parameters to the action, use the Data method and provide the name of a JavaScript function which will return a JavaScript object with the additional data:

.DataSource(source =>
{
    source.Read(read =>
    {
        read.Action("GetUsers", "CommonJsonActions").Data("additionalData");
    });
})

<script>
   function additonalData(){
      return {
            formType: $("#formType").val(),
        };
  }
</script>

This is assuming the other DropDownList has an id "formType". The action method should expect an additional parameter named "formType".

  • Related