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

Datasource From Injecting Service

1 Answer 149 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 12 Mar 2018, 10:19 PM

I have a  View with that I am injecting a service using @inject . The service provides Lookup list data that is not provided from the controller.

i.e. @inject ProfileOptionsData options

How would I set the datasource property to bind  the dropdownlist to a method from this service?

 

Thank you

1 Answer, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 15 Mar 2018, 11:00 AM
Hello Joe,

There is no built-in facility to bind the DataSource to a method from an injected service. 

You can, however, use the Items method of the DropDownList with an Action, where you can traverse the result of the service method and add the items dynamically. Similar to this example code: 

@(Html.Kendo().DropDownList()
    .Name("dropdownlist")
    .Items(items => {
        foreach (var item in options.MyMethod())
        {
            items.Add().Text(item.Text).Value(item.Value);
        }
    })
)


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