Search code examples
c#asp.net-mvckendo-uikendo-gridkendo-dropdown

MVC Kendo grid pass dropdownlist value to update method


I have a Kendo grid:

@(Html.Kendo().Grid<Grid>().Name("Grid")
      .DataSource(ds => ds
          .Ajax()
          .Model(model => model.Id(m => m.ID))
          .Read(read => read.Action("Grid_Read", "Sessions", new {sessionId = ViewBag.SessionID}))
              .Update(update => 
update.Action("Grid_Update", "Sessions", new { 
sessionId = ViewBag.SessionID, qcStateId = '????'}))
              .PageSize(10)
              .Batch(true)
          )
          .ToolBar(toolbar => 
          {
              toolbar.Template(
                    "| Set selected to: " + @Html.Partial("EditorTemplates/QCStatusHeader"));
          }
          )

QCStatusHeader:

@(Html.Kendo().DropDownList()
    .Name("QCStatusHeader")
    .DataValueField("Id")
    .DataTextField("Name")
    .BindTo((List<NomadBase.Web.ViewModels.Shared.QCStateViewModel>)ViewBag.PossibleQCStatesHeader)

)

How do I get the selected value from the QCStatusHeader dropdownlist into my update call to the controller?


Solution

  • Pretty simple solution, add the .Data option with a javascript method to return the currently selected value of the ddl.

    .Update(update => update.Action("Grid_Update", "Sessions", new {sessionId = ViewBag.SessionID})
        .Data("QCStatusHeaderValue"))
    
    function QCStatusHeaderValue() {
            var value = $('#QCStatusHeader').data("kendoDropDownList").value();
            return { qcStateId: value };
        }