ComboBox and passing additional data to controller

4 posts, 0 answers
  1. Joey
    Joey avatar
    2 posts
    Member since:
    Mar 2016

    Posted 07 Feb Link to this post

    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)
                                               
          )
  2. Nencho
    Admin
    Nencho avatar
    1663 posts

    Posted 09 Feb Link to this post

    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.
  3. Joey
    Joey avatar
    2 posts
    Member since:
    Mar 2016

    Posted 09 Feb in reply to Nencho Link to this post

    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.  
  4. Nencho
    Admin
    Nencho avatar
    1663 posts

    Posted 13 Feb Link to this post

    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.
Back to Top