javascript error when model for DropDownListFor is null

2 posts, 1 answers
  1. Alex
    Alex avatar
    75 posts
    Member since:
    May 2015

    Posted 07 Apr 2016 Link to this post


    I have a grid that has a column bound to it:

    columns.Bound(p => p.FailureStrategyLookup).ClientTemplate("#=FailureStrategyLookup.FailureStrategy#").Width(100);


    If the FailureStrategyLookup is NOT null, everything works fine. But when it IS NULL it can't bind the the object and I get an error saying "FailureStrategy" can't be found for a null value (or something to that affect). How can I get thsi working for a COMPLEX type when it's null?


    public class FailureStrategyLookupViewModel
        public int FailureStrategyID { get; set; }
        [DisplayName("Maintenance Strategy")]
        public string FailureStrategy { get; set; }



    @using eRPortalDashboard.Models;
    @using Kendo.Mvc.UI;
    @model FailureStrategyLookupViewModel
    @(Html.Kendo().DropDownListFor(m => m)

  2. Answer
    Vladimir Iliev
    Vladimir Iliev avatar
    2194 posts

    Posted 11 Apr 2016 Link to this post

    Hello Alex,

    From the provided information it seems that the source if the issue is the column template that you are using. In order to support null values you should access the nested fields only if the parent field is not null. Please check the updated code below:

    .ClientTemplate("#=FailureStrategyLookup ? FailureStrategyLookup.FailureStrategy : 'no value'#")

    Vladimir Iliev
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top