locked
input is not in the correct format RRS feed

  • Question

  •  I have a list of Country object

    public class Country
    {
      public int CountryID {get;set;}
      public string CountryName {get;set;}
    }
    
    
    // The CountryID if bound to this property of different object
    [DataMember]
    [Required(ErrorMessage = "Country is required.")]       
    public int CountryID
    {
                get
                {
                    return _countryid
                }
                set
                {
                    _countryid= value;
                    ValidateAndNotify(value, "CountryID");
                }
    }

    The country colletion is bind to a "CountryID" property of differt object.
    Using converter i convert the country object to int and vice versa. The problem is, if user does not select anything from the drop downlist and click save,The converter returns null
    and i get error "input is not in the correct format" and the validation summary shows "Can't convert type null type System.Int32"

    Why cant the required attributes get fired

    Monday, July 12, 2010 5:17 PM

Answers

  •  Whole model of databinding in Silverlight works based on reflection. When logic of your program tries to write value to ConutryID property it tries to convert it to System.Int32 and get error. Logic can't enter to setter of property.

    Monday, July 12, 2010 6:54 PM

All replies

  •  Whole model of databinding in Silverlight works based on reflection. When logic of your program tries to write value to ConutryID property it tries to convert it to System.Int32 and get error. Logic can't enter to setter of property.

    Monday, July 12, 2010 6:54 PM
  • it looks like i have to change my converter and instead of returning null it should return some other value (like -1), and then i need to write custom attribute to check against that value 

    Tuesday, July 13, 2010 10:50 AM
  • You can use RegularExpressionAttribute for validate property.

    Tuesday, July 13, 2010 5:12 PM