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

ComboBox and passing additional data to controller

3 Answers 1912 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Joey
Top achievements
Rank 1
Joey asked on 07 Feb 2017, 03:41 PM

So i have a ComboBox in a reusable partial view.  When i try to use getAddionalData and pass more parameters to the controller, is there a way i can pass the input of the combobox to the function?  I can't directly call it in the getAddionalData because there may be multiple and I won't know the exact id of which is calling the function.  I tried to use the 'this' qualifier in the function but that only gives me the url of the read.  For instance, on the dataBound function, i can call this.open() and it'll open my combobox.  I can't use that here.  Any idea?

@(Html.Kendo().ComboBoxFor(m=>m.Id)
                      .DataTextField("xxxx")
                      .DataValueField("xxxx")
                      .Placeholder("xxxx")
                      .MinLength(3)
                      .AutoBind(false)
                      .Events(e=>e.DataBound("functionCall").Change("functionCall"))
                      .TemplateId("templateId")
                      .HtmlAttributes(new { @class = "form-control", style = "width:100%" })
                      .Filter("contains")
                      .Delay(500)
                      .DataSource(source => source.Read(read => read.Action("method", "controller").Data("getAdditionalData(#=input.val()#)"))
                          .ServerFiltering(true))
                      .Height(500)
                                           
      )

3 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 09 Feb 2017, 11:57 AM

Hello Joey,

If I had correctly understood the scenario that you aim to pass the current input value of the demonstrated ComboBox to the method in the controller. If so, you can get a reference to that ComboBox, acquire its value and pass it as parameter. Please refer to the following forum thread and online demo, where this approach is used:


1. http://www.telerik.com/forums/cascade-combobox-and-passing-parameters-to-server#tsHj7-SD_kGvLj-wf02bNQ

2. http://demos.telerik.com/aspnet-mvc/combobox/cascadingcombobox



Regards,

Nencho
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Joey
Top achievements
Rank 1
answered on 09 Feb 2017, 02:58 PM
No, i can't call the id directly, like i said above "I can't directly call it in the getAddionalData because there may be multiple and I won't know the exact id of which is calling the function".  Multiple comboboxes will be using this function so it has to be dynamic.  
0
Nencho
Telerik team
answered on 13 Feb 2017, 11:42 AM
Hello Joey,

In order to achieve the desired functionality, you can pass a parameter to the partial view, where the combobox is nested in. When attempting to bind the ComboBox, eg when its DataSource.Read() method is triggered, you can set a value for a hidden field in the PartialView, where the combo is nested. Then, when the Data function is triggered, you can read the value of the hidden field and determine which widget initiated the binding.

In the attachment you can find a sample example on this implementation.

Note: scripts and packages are removed from the attachment, due to file upload limit.

Regards,
Nencho
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ComboBox
Asked by
Joey
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Joey
Top achievements
Rank 1
Share this question
or