DropDownList with dynamic parameter in DataSource

2 posts, 0 answers
  1. Anton.S
    Anton.S avatar
    2 posts
    Member since:
    Aug 2016

    Posted 05 Aug Link to this post

    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?

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    834 posts

    Posted 09 Aug Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top