I'm creating a grid for a model that has child relationship that is not required. The grid displays when the child has a value but if the child is null then I get a message that a value can't be null. For example. If my model is:
public class ProjectTypeViewModel
{
[Column("ManpowerProjectTypeID")]
public int ID { get; set; }
[StringLength(50)]
[Display(Name = "Project Type")]
public string ProjTypeDesc { get; set; }
[UIHint("ClientProjectType")]
public ProjectTypeComboViewModel ParentProjectType { get; set; }
}
public class ProjectTypeComboViewModel
{
[Column("ManpowerProjectTypeID")]
public int ID { get; set; }
[StringLength(50)]
[Display(Name = "Project Type")]
public string ProjTypeDesc { get; set; }
}
Then my grid looks like:
@(Html.Kendo().Grid<ManpowerForecast.Web.ViewModels.ProjectTypeViewModel>()
.Name("gridProjectType")
.Columns(columns =>
{
columns.Bound(c => c.ProjTypeDesc).Width(200);
columns.Bound(c => c.ParentProjectType).ClientTemplate("#=ParentProjectType.ProjTypeDesc#")
.Width(150);
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.HtmlAttributes(new { style = "height: 550px" })
.Refresh(true)
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(prop => prop.ID);
model.Field(b => b.ParentProjectType).DefaultValue(ViewData["defaultProjectTypes"] as ProjectTypeComboViewModel);
})
.Create(create => create.Action("CreateManpowerProjectTypes", "Manpower"))
.Read(read => read.Action("ReadManpowerProjectTypes", "Manpower"))
.Update(edit => edit.Action("UpdateManpowerProjectTypes", "Manpower"))
.Destroy(delete => delete.Action("DestroyManpowerProjectTypes", "Manpower"))
.PageSize(20)
)
)
this displays just fine as long as ParentProjectType has a value but if it is null I get an error in the browser consul that reads: ProjTypeDesc is null. If I comment out all the lines that have to do with the ParentProjectType the grid will display the data but off course doesn't contain the parent project type field. How do I indicate in the grid that the data isn't required or is nullable?