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

Inline Editing for Dropdown when empty returns [Object object]

2 Answers 462 Views
Grid
This is a migrated thread and some comments may be shown as answers.
StuartLittle
Top achievements
Rank 1
StuartLittle asked on 29 Oct 2018, 06:59 PM

Trying to implement inline editing. Following is a simplified version.

EmployeeEditor.cshtml inside EditorTemplates folder

@(Html.Kendo().DropDownList()
                .Name("ToBranch") 
                .DataValueField("Id") 
                .DataTextField("Name") 
                .BindTo((System.Collections.IEnumerable)ViewData["toBranch"]) 
)

 

Employee class

public class Employee

{

  public string EmployeeName {get; set;}

  [UIHint("EmployeeEditor"]

  public string ToBranch {get; set;}

}

 

View

@Html.Kendo().Grid(Model.Employees)
            .Name("BranchGrid")
            .Columns(col =>
            {
                col.Bound(o => o.EmployeeName);
                col.Bound(o => o.ToBranch);
                col.Command(command => { command.Edit(); });
            })
            .Editable(editable => editable.Mode(GridEditMode.InLine))
            .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model =>
            {
                model.Field(o => o.EmployeeName).Editable(false);
            })
            .Update(update => update.Action("EditingInline_Update", "BranchForm"))
            .ServerOperation(false))
            .Events(events => events.DataBound("error_handler"))
            .Render();

 

Controller

public ActionResult Index()

{

   //Populate a model

   ViewData["toBranch"] = branches 

   return View(model);

}

/////// Important Part

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingInline_Update([DataSourceRequest] DataSourceRequest request, Employee model)
{

//// If there was a branch initially say 24 and I change it to 28, I do see model.ToBranch as 28  ( works fine)

//// However, if the branch was initially an empty string and I change it to 28, model.ToBranch is "[Object object]"

}

 

Can you please tell me why this is happening? This is kind of critical and an urgent reply would be really appreciated

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Georgi
Telerik team
answered on 31 Oct 2018, 01:07 PM
Hello,

The issue is caused since the ToBranch field is of type string but its drop down editor is an object with Id and Name fields. What happens is when the user selects a value from the drop down an object is passed to the string field which is stringified and ends up as [Object object].

To avoid the issue I would suggest you to simply bind the drop down to a collection of strings (I assume Name values from current objects) and remove the DataValueField and DataTextField configuration.


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
StuartLittle
Top achievements
Rank 1
answered on 09 Nov 2018, 12:21 PM
Thank you very much Georgi. It worked.
Tags
Grid
Asked by
StuartLittle
Top achievements
Rank 1
Answers by
Georgi
Telerik team
StuartLittle
Top achievements
Rank 1
Share this question
or