MVC Dropdownlist inside Kendo MVC grids only selects first value.

2 posts, 0 answers
  1. Sanjeev
    Sanjeev avatar
    5 posts
    Member since:
    Jun 2015

    Posted 30 Jul 2015 Link to this post

    I have a grid which shows employee data and enable user to edit the data. When edit command is pressed, it displays dropdown list for one of the column(Name). The dropdown value gets displayed without any issue however when edit command is pressed, the existing value within the dropdown gets hidden and first value '- Select -....' get displayed.

    P.S: i followed this tutorial to add dropdown in Kendo Grid:

    Code Behind:

    class EmployeeItem
    public string Name{get; set;}
    public string Code1{get;set;}

    public string Code2{get;set;}​
    public string CombinedValues{get;set;}  //this is combination of Name, Code1, Code2 delimited by comma



      Controller Code:

    List<EmployeeItem> employeeList = service.GetEmployeeList();
    ViewBag.EmployeeList = new SelectList(employeeList, "CombinedValues", "Name");


    EditorTemplate Code (_EmployeeDropDown.cshtml):

          .OptionLabel("- Select - ")

    View Code:
          .Columns(columns =>
            columns.Command(command => { command.Edit(); }).Width("180px").Title("Action");
            columns.Bound(e => e.Name).Width("210px").EditorTemplateName("_EmployeeDropDown")

    So if the employeeList have values something like this:
    Name = John, Code1 = 1, Code2 = 2, CombinedValues = John,1,2
    Name = Matt, Code1 = 21, Code2 = 50, CombinedValues = Matt, 21, 50

    In the grid, when i first view the grid it displays the Name, John in first row, Matt in second row. If i edit Matt row, the dropdown will show up with '-Select-' as selected value instead of 'Matt'. 
    Does anyone know  how i can achieve that?
    Also, once i make selection on dropdown, let's say from Matt to John, and hit inline Save button now the value changes to CombinedValues i.e. John,1,2 instead of just John under Name column.

  2. Georgi Krustev
    Georgi Krustev avatar
    3747 posts

    Posted 04 Aug 2015 Link to this post

    Hello Sanjeev,

    In general, the name of the widget should be equal to the model field, which in this case is "Name". I would suggest you set the name of the widget correctly. I would suggest you review the "Editing custom editor" demo and more specifically the offline demos part of the UI for ASP.NET MVC bundle. Thus you can review and even debug the whole demo locally.

    You can also check our list of MVC demos available in this Github repository:
    Georgi Krustev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top