I have a Supplier Entitiy that contains
ID - int
Status - string
Name - string
CreateDate- datetime
I am using the partial class method to create Data Annotations for the above Entity.as described here
[MetadataType(typeof(SupplierMetadata))]
public partial class Supplier
{
// Note this class has nothing in it. It's just here to add the class-level attribute.
}
public class SupplierMetadata
{
// Name the field the same as EF named the property - "FirstName" for example.
// Also, the type needs to match. Basically just redeclare it.
// Note that this is a field. I think it can be a property too, but fields definitely should work.
[HiddenInput]
public Int32 ID;
[Required]
[UIHint("StatusList")]
[Display(Name = "Status")]
public string Status;
[Required]
[Display(Name = "Supplier Name")]
public string Name;
}
the HiddenInput annotation throws an error saying “Attribute ‘HiddenInput’ is not valid on this declaration type. It is only valid on ‘class, property, indexer’ declarations.”
Please help
The error states that that attribute can only be added to ‘class, property, or indexer declarations’.
public Int32 ID;is none of these – it is a field.If you change it to a property
public Int32 ID { get; set; }you will be able to decorate it with that attribute.