Search code examples
c#asp.net-mvckendo-uidropdownlistfor

passing value of kendo DropDownListFor to read action of another DropDownListFor


I have a DropDownListFor component which has a read action which gets values from the database. However, I want to filter those values based on the value of another DropDownListFor.

Here's the DropDownListFor component that has the filter value

        <div class="editor-field">
                        @(Html.Kendo().DropDownListFor(model => model.ReleaseID)
                        .DataTextField("Value")
                        .DataValueField("Key")
                        .DataSource(ds => ds 
                            .Read(read=>read.Action("GetReleases", "Task"))
                            ) 
                        ) 
            @Html.ValidationMessageFor(model => model.ReleaseID)
          </div>

What I want to do is pass the value of ReleaseID into the read action of another DropDownListFor. I tried to do it like this:

                <div class="editor-field">
                @(Html.Kendo().DropDownListFor(model => model.MarketModelID)
                      .Events(e => e.Select("onSelectMarketModel"))
                      .Template("<span data-title='Model Description: #: data.Item3 #'>#: data.Item2 # </span>")
                      .DataTextField("Item2")
                      .DataValueField("Item1")
                      .DataSource(ds => ds
                          .Read(read => read.Action("GetMarketModels", "Task", new { release = Model.ReleaseID }))
                  )) 
                @Html.ValidationMessageFor(model => model.MarketModelID)
            </div>

with the controller method signature:

public JsonResult GetMarketModels(int? release)
{
    //code to get market models based on release
}

However, the release in GetMarketModels method is always 0 no matter what the selection is for the ReleaseID DropDownFor at the top. What am I doing wrong?

Thank you.


Solution

  • You need to use cascading DropDownLists. Here you can find an example of how to create cascading DropDownLists:

    Cascading DropDownList