ComboBoxFor returns "Object reference not set to an instance of an object" error

1 posts, 0 answers
  1. Babu
    Babu avatar
    3 posts
    Member since:
    Sep 2011

    Posted 04 Oct 2012 Link to this post

    Hi,

    I have a Kendo comboboxfor on my view and the datasource comes from my model as an IEnumerable<SelectListItem>.  But running the page crashes with the subject error message.  If I change the CombBoxFor to ComboBox and attach the datasource with the dataSource method, it seem to work.  What is wrong here: 

    Here is my View (code is partial):
    <li>
      @Html.LabelFor( m => m.FKStatusTypeId )
      @(Html.Kendo()
              .ComboBoxFor( m => m.FKStatusTypeId )
              .BindTo( Model.StatusTypeList)
      )
    </li>

    and here is my Model (code is partial):
    [Display( Name = "Status" )]
    public int FKStatusTypeId { get; set; }
     
    // use as @Html.DropDownListFor(m => m.FKBillingTypeId, Model.BillingTypeList, "--select--")
    //        @Html.ValidationMessageFor(m => m.FKBillingTypeId)
     
    [Display( Name = "Zip Code" )]
    [Required( ErrorMessage = "Zip Code is required" )]
    [ZipCodeOnly( ErrorMessage = "Zip code is not valid" )]
    [ValidateZipCode( ErrorMessage = "ZipCode is not valid" )]
    public string Zip5 { get; set; }
     
    public SelectList ZipCities { get; set; }
     
    public IEnumerable<SelectListItem> StatusTypeList
    {
       get
       {
         var ctx = new PCDataEFContext();
         var sTypes = ctx.StatusTypes;
         var items = sTypes.Where( st => st.PKId > 0 )
                       .ToList()
                       .Select( st => new SelectListItem
                             {
                               Text = st.Name,
                               Value = st.PKId.ToString()
                             } );
         return items;
       }
    }

    What am I doing wrong here?

    Babu.



Back to Top