KendoUI ComboBoxFor doesn't bind on post

8 posts, 1 answers
  1. Mika
    Mika avatar
    5 posts
    Member since:
    Sep 2012

    Posted 05 Dec 2012 Link to this post

    I have the following ComboBox on my view
    @(Html.Kendo().ComboBoxFor(m => m.CurrentBooking.Resource.ResourceId)
        .Name(
    "resourceAutoComplete")
        .DataTextField(
    "ResourceName")
        .DataValueField(
    "ResourceId")
        .BindTo(Model.Resources)
        .Placeholder(
    "Select resource"))
    But in my Save() action the Model.CurrentBooking.Resource is always null, and Model.CurrentBooking.ResourceId is always 0.

    What am I doing wrong in my ComboBoxFor() configuration?
  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 05 Dec 2012 Link to this post

    Hello,

     
    When strongly bound HTML helper is used, a.k.a ComboBoxFor<T>, do not set the Name manually. I will suggest you remove the Name method of the declaration of the widget.

    Regards,
    Georgi Krustev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Mika
    Mika avatar
    5 posts
    Member since:
    Sep 2012

    Posted 05 Dec 2012 Link to this post

    Thank you, removing the Name -method fixed the issue :)
  5. Douglas
    Douglas avatar
    1 posts
    Member since:
    Aug 2013

    Posted 26 Dec 2013 Link to this post

    This fixed my problem but why is it causing the problem? Is this a bug?
  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Dec 2013 Link to this post

    Hello Douglas,

    No, this is not a bug. This is the way ASP.NET MVC model binding works. It expects the name of the input to match the property name of the model. If there is no such match then it won't work.

    More info can be found in this blog post.

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  7. Gerber
    Gerber avatar
    5 posts
    Member since:
    May 2014

    Posted 06 Jun 2014 in reply to Atanas Korchev Link to this post

    Hi - going back on this one... if I remove the Name.. how will Cascading works? In my case, cascading no longer works.
    Thanks,
    Gerber
  8. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 10 Jun 2014 Link to this post

    Hello Gerber,

    In order for cascading to work you need to specify the actual ID of the parent combobox - the one that ASP.NET MVC has generated for it. You can either inspect the generated HTML output to get the actual ID or override the ID of the combobox via the HtmlAttributes method:

    @(Html.Kendo().ComboBoxFor().HtmlAttributes(new { id = "myid" })

    @(Html.Kendo().ComboBoxFor().CascadeFrom("myid"))

    Regards,
    Atanas Korchev
    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.

     
  9. ajith
    ajith avatar
    21 posts
    Member since:
    Apr 2015

    Posted 20 May 2015 in reply to Atanas Korchev Link to this post

    Hi, Atanas

        When i try to cascade comboboxfor, it wil hides other comboboxes. 

    @(Html.Kendo().ComboBoxFor(m => m.SubgroupCode)
     
                 .HtmlAttributes(new { style = "width:160px", id = "Subgroupid" })
                 .Placeholder("Select product...")
                 .DataTextField("Name")
                 .DataValueField("ID")
                 .Filter(FilterType.Contains)
                 .DataSource(source =>
                 {
                     source.Read(read =>
                     {
                         read.Action("GetAssetSubgroup", "Asset").Data("filterSubGroups");
     
                     })
                     .ServerFiltering(true);
                 })
                 .Enable(false)
                 .AutoBind(false)
                 .CascadeFrom("groupid")
           )
                       <script>
                           function filterSubGroups() {
                               return {
                                   groups: $("#groupid").val(),
                                   groupfilter: $("#Subgroupid").data("kendoComboBox").input.val()
                               };
                           }
                       </script>
                   </td>

     

     

    please help me

Back to Top
UI for ASP.NET MVC is VS 2017 Ready