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

Cascading DropDownList setting to Model value

2 Answers 357 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Veteran
Robert asked on 05 Oct 2020, 07:25 PM

I have two dropdowns, the second "cascading" from the first.  This works fine except that when the user first goes into the page, the model has the values for the first and second dropdowns (Model.ProgramID and Model.StrategyID).  The first dropdown selects the correct item in the list, but the second dropdown (the cascade one) does not automatically select the item equal to the value from the model, it just selects the first item in the list.  If I turn cascading "off" and just load them without cascading stuff set, they both get set to the correct selected items in their respective dropdowns based on the values in the model.

<div class="form-input-group">
    <label>Program</label>
    @(Html.Kendo().DropDownList()
    .Name("ProgramID")
    .DataTextField("Display")
    .DataValueField("Value")
    .HtmlAttributes(new { style = "width:100%" })
    .OptionLabel("Select")
    .DataSource(s =>
    {
        s.Read(r =>
        {
            r.Action("RemoteDataSource_GetFirmPrograms", "DropDownList", new { userAccountID = Model.UserAccountID, firmID = Model.FirmID });
        });
    })
    .Height(290)
)
</div>
 
<div class="form-input-group">
    <label>Strategy</label>
    @(Html.Kendo().DropDownList()
    .Name("StrategyID")
    .DataTextField("Display")
    .DataValueField("Value")
    .HtmlAttributes(new { style = "width:100%" })
    .OptionLabel("Select")
    .DataSource(s =>
    {
        s.Read(r =>
        {
            r.Action("RemoteDataSource_GetFirmStrategies", "DropDownList").Data("filterStrategies");
        })
       .ServerFiltering(true);
    })
    .Height(290)
    .AutoBind(true)
    .CascadeFrom("ProgramID")
)
</div>

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 07 Oct 2020, 02:12 PM

Hello Robert,

Thank you for the code snippets.

Unfortunately I cannot see how are you binding the model field values to the DropDownLists. Could you please provide some information about that? Once I am more aware of the details, I will be happy to assist you.

Looking forward to your reply.

Regards,
Martin
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

0
Robert
Top achievements
Rank 1
Veteran
answered on 08 Oct 2020, 12:27 PM
Not sure what I did, but it started working.  Go figure.
Tags
DropDownList
Asked by
Robert
Top achievements
Rank 1
Veteran
Answers by
Martin
Telerik team
Robert
Top achievements
Rank 1
Veteran
Share this question
or