This question must have been asked before but couldn't find it.
I know that by creating a custom model binder, I can process data entered by users. There are examples of trimming string properties. Here's an example of that: ASP.NET MVC: Best way to trim strings after data entry. Should I create a custom model binder?
My question is how to control when to process or not process by using custom attributes.
For example, I may want to automatically capitalize the first letter of string properties only if I have an attribute that indicates it like below:
public class MyModel
{
[CapitalizeFirstLetter]
public string FirstName { get; set; }
[CapitalizeFirstLetter]
public string LastName { get; set; }
public string UserName { get; set; }
}
In this example, first and last name properties will get processed but not the username although all three are string properties.
How do I handle this?