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

DropDownList not binding correctly on update in grid

7 Answers 790 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 08 May 2014, 08:39 PM
I have a grid that is bound client-side.  It has create/update.

One of the fields has a dropdown list using the OptionLabel for an editor template (see Image1).  When creating a record on the grid, selecting an option other than the OptionLabel option save fine (see Image2).

When updating the record and selecting the OptionLabel option, everything saves fine (see Image3).

When updating again, all of the options save as [option Option] even though the dropdown list displays correctly (see Image4).

The easiest way to see this is by using the PopUp edit option and never refreshing the page.

7 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 12 May 2014, 09:55 AM
Hi Michael

I would suggest to try setting the ValuePrimitive option of the DropDownList to true:

@(Html.Kendo().DropDownList()
      .Name("SomeName")
      .ValuePrimitive(true)

Kind Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Michael
Top achievements
Rank 1
answered on 12 May 2014, 02:08 PM
That worked, thank you.
0
Theunis
Top achievements
Rank 1
answered on 30 Sep 2014, 06:22 AM
[quote]Vladimir Iliev said:Hi Michael

I would suggest to try setting the ValuePrimitive option of the DropDownList to true:

@(Html.Kendo().DropDownList()
      .Name("SomeName")
      .ValuePrimitive(true)

Kind Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
[/quote]

This has not worked for me. Any other suggestions?
0
Vladimir Iliev
Telerik team
answered on 30 Sep 2014, 07:36 AM
Hi Theunis,

From the provided information it's not clear for us what is the exact setup that you have - could you please open new support thread / forum post and provide the current Grid code, editor templates and model that you are using? This would help us pinpoint the exact reason for this behavior.

Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chris
Top achievements
Rank 1
Veteran
Iron
Iron
answered on 12 Jun 2018, 01:56 PM

HI

I have the similar problem and I have tried the aspnetmvc\Examples\VS2015\Kendo.Mvc.Examples\Views\grid\editing_popup.cshtml.

  Grid Popup Edit : 

        [UIHint("CategoryID2")]
        public string CategoryID2 { get; set; }

In my EditorTemplates, the DropDownList get the list by using Action : 

@model object

@(Html.Kendo().DropDownListFor(m => m)
        .DataValueField("Value")
        .DataTextField("Text")
          .ValuePrimitive(true)
        .DataSource(source =>
        {
          source.Read(read =>
          {
            read.Action("GetCategories", "Grid") ;
          });
        })
)

In Update action, I got the CategoryID2 = "[object Object]" before ValuePrimitive(true),
and got the CategoryID2 = "0004" after ValuePrimitive(true) : 

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult EditingPopup_Update([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
        {

MY QUESTIONS ARE : 

.Why the DropDownList in Grid Popup Edit need the ValuePrimitive(true) ? 
.Why the general DropDownList (standlone DropDownList) do not need the ValuePrimitive(true) ? 
.Why the DropDownList.ValuePrimitive do not default to true (Control built-in) ? 

I think the DropDownList.ValuePrimitive default to false is very very very UNREASONABLE in physical implementation.

*Telerik DevCraft/UI for ASP.NET MVC R2 2017 SP1.

Best regards

Chris

 

 

0
Chris
Top achievements
Rank 1
Veteran
Iron
Iron
answered on 12 Jun 2018, 03:02 PM

>Why the general DropDownList (standlone DropDownList) do not need the ValuePrimitive(true) ? 

 

means BindTo(IEnumerable<SelectListItem>) method.

0
Tsvetina
Telerik team
answered on 14 Jun 2018, 10:18 AM
Hi Chris,

The valuePrimitive settings comes in effect when the DropDownList is bound to a model, it has no effect on a DropDownList that does not have a value binding applied.

When the DropDownList is bound to a field of a model, the valuePrimitive setting determines the binding behavior of the DropDownList. If set to true, the underlying Grid model field will be updated with the selected item value field. If set to false, the Grid model field will be updated with the entire selected data item (with all its properties).

You can see, in the following example, that even a regular DropDownList, when put in an MVVM binding scenario needs the valuePrimitive setting to configure its binding behavior:
http://dojo.telerik.com/@tsveti/ABoZOxuL

The value binding behavior of list widgets (DropDownList, ComboBox, etc.) is explained in this article:
View-Model Fields with Value Field of Primitive Value

This behavior has been the default for quite some time now and changing it would be a breaking change in a lot of customer projects.

Regards,
Tsvetina
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Michael
Top achievements
Rank 1
Theunis
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Veteran
Iron
Iron
Tsvetina
Telerik team
Share this question
or