This is a migrated thread and some comments may be shown as answers.

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

0 Answers 100 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Babu
Top achievements
Rank 1
Babu asked on 04 Oct 2012, 02:59 PM
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.



No answers yet. Maybe you can help?

Tags
ComboBox
Asked by
Babu
Top achievements
Rank 1
Share this question
or