DropDownList not binding correctly on update in grid

8 posts, 1 answers
  1. Michael
    Michael avatar
    4 posts
    Member since:
    Apr 2013

    Posted 08 May 2014 Link to this post

    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.
  2. Answer
    Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2204 posts

    Posted 12 May 2014 Link to this post

    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.

     
  3. Michael
    Michael avatar
    4 posts
    Member since:
    Apr 2013

    Posted 12 May 2014 in reply to Vladimir Iliev Link to this post

    That worked, thank you.
  4. Theunis
    Theunis avatar
    2 posts
    Member since:
    Jul 2014

    Posted 30 Sep 2014 in reply to Vladimir Iliev Link to this post

    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.

     


    This has not worked for me. Any other suggestions?
  5. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2204 posts

    Posted 30 Sep 2014 Link to this post

    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.

     
  6. Chris
    Chris avatar
    119 posts
    Member since:
    Oct 2015

    Posted 12 Jun 2018 Link to this post

    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

     

     

  7. Chris
    Chris avatar
    119 posts
    Member since:
    Oct 2015

    Posted 12 Jun 2018 in reply to Chris Link to this post

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

     

    means BindTo(IEnumerable<SelectListItem>) method.

  8. Tsvetina
    Admin
    Tsvetina avatar
    2481 posts

    Posted 14 Jun 2018 Link to this post

    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.
Back to Top