binding to int? not working

7 posts, 0 answers
  1. MelF
    MelF avatar
    11 posts
    Member since:
    Aug 2012

    Posted 26 Sep 2012 Link to this post

    if I bind to a nullable integer which has an initial value of null, the combobox always returns a null value value to the controller, even if a value has been selected. if I change it to work with a  standard integer, it returns the correct value, but it also sets an initial value in the list which I do not want.

    thoughts?

    no initial value, but not updating either: public int? QuoteId { get; set; } 
    returning values as expected, but populating 0: public int QuoteId { get; set; } 

    @(Html.Kendo().ComboBoxFor(m => m.QuoteId)
                      .DataSource(dataSource => dataSource
                                                    .Read(read => read.Action("GetQuoteList", "Payment")))
                      .DataTextField("Text")
                      .DataValueField("Value")
                      )
  2. Murat
    Murat avatar
    1 posts
    Member since:
    Oct 2012

    Posted 29 Oct 2012 Link to this post

    Even if you change int to nullable int into your demo. GridForeignKey.aspx getting same behaviour.
  3. Kendo UI is VS 2017 Ready
  4. MelF
    MelF avatar
    11 posts
    Member since:
    Aug 2012

    Posted 19 Nov 2012 Link to this post

    same difference. Any ideas? this is continuing to be a problem for me.
  5. Mind of Neeko
    Mind of Neeko avatar
    1 posts
    Member since:
    Sep 2012

    Posted 30 Nov 2012 Link to this post

    MelF,

    We had this same Issue and this was our "Work Around".

    I am going to make a few assumptions.

    1. You are using a [site].Domain and [site].WebUI project set up in your solution.
    2. You are using Concrete/Abstract/Entity in your .Domain project
    3. You are using Model/View/Controller in your .WebUI project.
    4. You are performing your queries in the Controller against your .Domain repositories.
    5. I haven't lost you so far :D.

    So what we did was:

    1. In the Controller Action to "GET" the data for our Combo Box we added a "null" value
        a. ex. Select CompanyID = a.CompanyID == null ? 0 : a.CompanyID
            i. This basically populates your model with a 0 if the DB result is NULL.

    2. In the Page in which the Combo Box lives you will now see a "0" value if the DB value is NULL
        a. Making this more user friendly is another topic.

    3. In the Controller Action that handles the "POST" of your form we do the opposite to 1.
        a. ex Insert CompanyID = a.CompanyID == 0 ? null : a.CompanyID


    We basically forced the Combo Box to process a "0" record if one does not exist, then on the Insert Portion we remove the "0" and set it back to null.
  6. Rock
    Rock avatar
    1 posts
    Member since:
    Jan 2013

    Posted 07 Jan 2013 Link to this post

    i have same error.

    i using your solution.
    but a problem,
    When opening a new form , not saving data of combobox!
    No principled solution?
  7. Janette
    Janette avatar
    2 posts
    Member since:
    Feb 2013

    Posted 13 Feb 2013 Link to this post

    unfortunately none of these solutions would work if you have data with an Id = 0.  may be poor data design, but very common. Sending a project directly to telerik.  I will report back with any findings
  8. Janette
    Janette avatar
    2 posts
    Member since:
    Feb 2013

    Posted 15 Feb 2013 Link to this post

    this issue is easily resolved with 2 modifications:

    • DO NOT name your drop-down
    • add this to your validation

    <script>
        $.validator.setDefaults({
            ignore: ""
        });
    </script>
Back to Top
Kendo UI is VS 2017 Ready