In my application I have many properties like
[DisplayFormat(ApplyFormatInEditMode=false,ConvertEmptyStringToNull=false,DataFormatString="{0:0.00}")]
public decimal somedecimalvalue { get; set; }
Is there any way i can generalize this whenever a decimal property is created above format is applied to it
You can manually assign metadata for decimal properties in your models by creating custom
DataAnnotationsModelMetadataProvider:And then register this provider in Global.asax.cs in
Application_Start()method:Then you can remove
DisplayFormatattribute from decimal properties. Note that this won’t affect other properties and you can safely add other data annotations on your decimal properties.Read more about MetaData class and its properties.
Happy coding! 🙂