MVC Model.IsValid for enumerations

blidgiffivord

New Member
I have a web page that has a dropdown populated by an enumeration. \[code\] public enum RegionType{ State, [System.Xml.Serialization.XmlEnumAttribute("County/District")] County_District, [System.Xml.Serialization.XmlEnumAttribute("City/Town")] City_Town, Municipality, Village}\[/code\]the dropdown actually expresses the enumeration through the following method:\[code\] public static List<string> GetRegionTypes(){ List<string> theReturn = new List<string>(); theReturn.Add(""); foreach (RegionType s in Enum.GetValues(typeof(RegionType))) { theReturn.Add(GetXmlEnumValue(s)); } return theReturn;}\[/code\]works great, the dropdown shows with the correct values and everything. the problem is with the 2 values that i have the 'xmlenum' attribute. If i choose as a region type 'Country/District' or 'City/Town', the model's 'RegionType' property can't translate that to the corresponding enumeration in the MVC controllers POST action. How do i get it to do the translation properly?
 
Back
Top