In MVC3 how would I create a custom attribute to a strongly defined class (apologies about terminology, I’m learning as I go here) so that I can use it like:
[CustomValue(AttributeMappingName = "first.name")]
I would like to be able to display ‘first-name’ within my view, I realise this is static for every Patient_FirstName but I wish to access a custom mappingname client side.
Context:
public class FormStandard_Model
{
[Required()]
[Key]
public string My_ID { get; set; }
[Required]
[StringLength(32, MinimumLength = 2)]
[Display(Name = "First Name")]
[CustomValue(AttributeMappingName = "first.name")]
public string Patient_FirstName { get; set; }
}
Sounds like you need to create a custom
ModelMetadataProviderso that the data in your custom attribute will be available in your view. See this answer:Custom Data Annotations ASP.NET MVC C#