hello I am trying to do validation to my form and I obtain this error!!!
Error 10 The type or namespace name ‘DataAnnotations’ does not exist
in the namespace ‘System.ComponentModel’ (are you missing an assembly
reference?)
How can i fix it?
I use “using System.ComponentModel.DataAnnotations;” in other model and work fine…
but I have this other model:
public class CompuViewModel
{
public List<Compu> PackageCompu { get; set; }
}
public class Compu
{
public int Id { get; set; }
public string Name { get; set; }
}
I try to put [Require] in all fields, but throws the error!
Any idea?
You can fix this by stop considering error messages a “bad thing”. Once you do that, you’ll be capable of reading the error message and also understand that it’s simply a good thing that you are seeing it and not the end user.
The system is trying to help you notice it before it’s too late and even in this particular error, it’s even asking you helpfully “Are you missing an assembly reference” prior to that, it’s even telling you that it’s looking for “DataAnnotations” in “System.ComponentModel” and can’t find it. Now, you need to help it a little.
So
So, it’s looking for DataAnnotations in System.ComponentModel and it’s guessing your missing an assembly reference.
Now, to add an assembly reference:
Done