Search code examples
c#asp.netasp.net-mvcasp.net-mvc-4asp.net-mvc-5

asp.net mvc dropdownlist with null database value not binding to dropdownlist correctly


I have a list of colleges with collegeid, college coming from the datatabase. the collegeID starts with 0 in the database. I have some records in the database for faculty where the collegeid is null. the dropdown list is binding to the 0 collegeID instead of the "----Please Select---" that has an empty string value. How can I get the records in the database that are null to default to the "---Please select---" list item in the dropdownlist?


Solution

  • Have you set your collegeId to nullable. If not,set it to nullable so that its default value is always null

    public int? CollegeId {get;set;}