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

Passing current DropDown as parameter

1 Answer 551 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Ezequiel
Top achievements
Rank 2
Ezequiel asked on 10 Jul 2015, 07:52 PM

 

I have a EditorTemplate which is:

@model string
 
@(this.Html.Kendo().DropDownList()
    .Name(this.ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
    .Value(this.Model)
    .HtmlAttributes(new { style = "width: 220px;"})
    .OptionLabel("Select)
    .DataValueField("Value")
    .DataTextField("Text")
        .DataSource(ds => ds.Read(read => read.Action("GetList", "Combo").Data("getAdditionalParam")))
)

I want to get this dropdown in my function:

function getAdditionalParam(dropDown){
//do stuff with dropDown

//

 return { additionParam: 1 }
}

 

Is there anyway to pass the object itself as parameter?

 

Thanks,

Ezequiel

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 14 Jul 2015, 11:41 AM
Hello Ezequiel,

Basically, you will need to get an instance of the widget in the getAdditionalParam function. The code should look something like that:
function getAdditionalParam(e){
var id = "#@(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))";
var widget = $(id).data("kendoDropDownList");
 
//get widget value
var value = widget.value();
 
//get the selected data item
var dataItem = widget.dataItem();
 
 return { additionParam: 1, item: dataItem }
}

If you would like to pass an object then you can just add it to the object. Note that ASP.NET MVC is responsible for parsing this object and you need to configure the Action method correctly in order to receive it correctly populated.

Regards,
Georgi Krustev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DropDownList
Asked by
Ezequiel
Top achievements
Rank 2
Answers by
Georgi Krustev
Telerik team
Share this question
or