When I 'm using the DataAnnotationModel for form validation with a List datastructure in the model, I get a NullReferenceException on form submit. How do handle the situation.
My model contains
public class GroupModel:ModelBase { [Required(ErrorMessage = "Primary Group Name required")] public string PrimaryGroupName { get; set; }
[Required(ErrorMessage = "Secondary Group Name required")]
public string SecondaryGroupName { get; set; }
public List<DeviceGroupModel> PrimaryDeviceGroups { get; set; }
public List<DeviceGroupModel> SecondaryDeviceGroups { get; set; }
}
My view contains
<%=Html.TextBox("PrimaryGroupName")%>
<%=Html.ValidationMessage("PrimaryGroupName","*") %>
Group Name:
<%=Html.TextBox("PrimaryDeviceGroups[0].Name")%>
<label for="GroupName">Group Name:</label>
<%=Html.TextBox("PrimaryDeviceGroups[1].Name")%>
<br /><br />
<b> Secondary Gorups</b>
Type Name:
<%=Html.TextBox("SecondaryGroupName")%>
<%=Html.ValidationMessage("SecondaryGroupName","*") %>
Group Name:
<%=Html.TextBox("SecondaryDeviceGroups[0].Name")%>
Group Name:
<%=Html.TextBox("SecondaryDeviceGroups[1].Name")%>