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

DropDownList with dynamic parameter in DataSource

1 Answer 2405 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Anton.S
Top achievements
Rank 1
Anton.S asked on 05 Aug 2016, 02:01 PM

Greetings!

 

I've implemented an EditorTemplate that uses Kedno.DropDownList for one of the model properties. Here is an example of it

1.@(Html.Kendo().DropDownList()
2.          .Name(ViewData.ModelMetadata.AdditionalValues["id"].ToString())
3.          .OptionLabel("not selected")
4.          .DataTextField("Name")
5.          .DataValueField("Id")
6.          .DataSource(ds => ds.Read(a => a.Action("GetAvailiableOrders","Orders")))
7.          .Filter(FilterType.Contains)
8.

I use this model to populate grid, like so

01.@(
02.    Html.Kendo().Grid<CustomerViewModel>()
03.    .Name("customersGrid")   
04.    .ToolBar(toolbar =>
05.    {
06.        if (!Model.ReadOnly)
07.        {
08.            toolbar.Create();
09.        }
10.    })
11.    .Editable(e => e.Mode(GridEditMode.InLine).CreateAt(GridInsertRowPosition.Bottom))
12.    .Resizable(resize => resize.Columns(true))
13.    .Columns(c => {
14.        c.Bound(s => s.Order); //EditorTemplate will be used here
15.        c.Bound(s => s.ConsumerName).Format("{0:dd.MM.yyyy}");
16.        c.Bound(s => s.OrderDate).Format("{0:dd.MM.yyyy}");
17.        if (!Model.ReadOnly)
18.        {
19.            c.Command(command =>
20.            {
21.                command.Edit();
22.                command.Destroy();
23.            });
24.        }
25.    })
26.    .DataSource(d => d.Ajax().
27.    Model(m =>
28.    {
29.        m.Id(p => p.Id);
30.        m.Field(p => p.Id).DefaultValue(default(long));
31.    })
32.    .Read(a => a.Action("GetCostumers","Costumers"))
33.    .Create(a => a.Action("CreateCostumer", "Costumers"))
34.    .Update(a => a.Action("UpdateCostumer","Costumers"))
35.    .Destroy(a => a.Action("DeleteCostumer", "Costumers"))
36.    )
37.)

I need some how to pass additional argument to the DataSource Read method,this parameter depends on other model property an is uiniqe for each grid row.

.DataSource(ds => ds.Read(a => a.Action("GetAvailiableOrders","Orders"))) //Need to pass additional argument here dependting on current row

Is there any way to implement this?

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 09 Aug 2016, 09:01 AM
Hello Anton,

Please see the following thread, which shows the available ways to pass parameters and how to access the data in the controller.

Regards,
Ivan Danchev
Telerik by Progress
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
Anton.S
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or