views:

18

answers:

2

I have a class like this

public  class MyClass 
{
    public MyClass()
    {
        Enumlist = new List<MyEnum>();
    }     
    public virtual List<MyEnum> Enumlist { get; set; }
}

and the enum is

public enum MyEnum
{
    Enum1=1,
    Enum2=2,
    Enum3=3
}

but in my view i keep having this eror

"The value 'System.Collections.Generic.List`1[MyEnum]' is not valid for Enumlist"

I did not specify any validation attribute for the property EnumList, so i don't why the automatic error.

Please, can someone help with this?

A: 

In Asp.Net MVC 2 it is a default behaviour of DataBinding. If you have a Date field in your model it will automatically add validation error when the binding fails for the date. Same is true for enum.

Amitabh
@Amitabh, thanks for the answer. I have used DateTime and enum properties with success, but this particular problem is with a list of enums as shown in the sample code above.
yayadavid
A: 

I do not know if a list of an enum type is illegal in ASP.Net MVC but i solved this problem by using enum flag attribute and bit operations on the enum to combine the enum values.

This article (http://www.codeproject.com/Articles/37921/Enums-Flags-and-Csharp-Oh-my-bad-pun.aspx) on codeproject could help anyone having this same problem.

Happy coding.

yayadavid