c.IndustryName).Title("Industry").EditorTempl" /> c.IndustryName).Title("Industry").EditorTempl" /> c.IndustryName).Title("Industry").EditorTempl"/>

Kendo Dropdown not retaining value when clicking on Inline Edit

53 Views Asked by At

When I click on inline edit button, column titled "Industry" do not retain its value.

columns.Bound(c => c.IndustryName).Title("Industry").EditorTemplateName("AppPackIndEditor").Filterable(ftb => ftb.Extra(false).Operators(Operator => Operator.ForString(str => str.Clear().Contains("Contains")))).Width(120);

This is the code for the editor :

@using Kendo.Mvc.UI

@{
    ViewBag.Title = "AppPackIndEditor";
}

@(Html.Kendo().DropDownListFor(m => m)
                  .Name("IndustryName")
                  .SelectedIndex(0)
                  .Filter(FilterType.StartsWith)
                  .DataTextField("IndustryName")
                  .DataValueField("IndustryId")
                  .HtmlAttributes(new { style = "text-align: center;", required = "required", validationmessage = "Select Industry" })
                  .BindTo((System.Collections.IEnumerable)ViewData["Industry"])
                  .Events(x => x.Change("onChangeDropDown").Change("IndustryChange"))
                  .OptionLabel("--- Select ---")
                  .NoDataTemplateId("noDataTemplate")
                  )

I have tried renaming the property name etc but the issue still persists

1

There are 1 best solutions below

1
Aleksandar On

When using the DropdownListFor(m=>m) there is no need to set the Name() options. With the provided configuration the entire dataItem will be set as value for the IndustryName model property. Add the ValuePrimitive(true) so the value of the dataItem's field as set in the DataValueField is set as value of the IndustryName property. If the IndustryName is a string you can update the editor the following way:

@(Html.Kendo().DropDownListFor(m => m)
              .Filter(FilterType.StartsWith)
              .DataTextField("IndustryName")
              .DataValueField("IndustryName")
              .HtmlAttributes(new { style = "text-align: center;", required = "required", validationmessage = "Select Industry" })
              .BindTo((System.Collections.IEnumerable)ViewData["Industry"])
              .Events(x => x.Change("onChangeDropDown").Change("IndustryChange"))
              .OptionLabel("--- Select ---")
              .NoDataTemplateId("noDataTemplate")
              )