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

javascript error when model for DropDownListFor is null

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 07 Apr 2016, 09:00 PM

 

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
{
    [Required]
    public int FailureStrategyID { get; set; }
 
    [Required]
    [DisplayName("Maintenance Strategy")]
    public string FailureStrategy { get; set; }
}

ssdsdf

 

@using eRPortalDashboard.Models;
@using Kendo.Mvc.UI;
 
@model FailureStrategyLookupViewModel
 
@(Html.Kendo().DropDownListFor(m => m)
    .DataValueField("FailureStrategyID")
    .DataTextField("FailureStrategy")
    .BindTo((System.Collections.IEnumerable)TempData["FailureStrategyLookups"])
)

sadasd

1 Answer, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 11 Apr 2016, 10:17 AM
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'#")

Regards,
Vladimir Iliev
Telerik
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
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or