I'm trying to make a more customized data annotation for one of attributes. In my data model, I have an attribute:
public int AutoCallableStart { get; set; }
And I want to display it like this: 1 --> "1st" 2 --> "2nd" 3 --> "3rd", ..., etc.
In a view model implementation (my current implementation), I have:
public string CallFrom
{
get
{
switch (_callableIncome.AutoCallableStart)
{
case 1:
return "1st";
case 2:
return "2nd";
case 3:
return "3rd";
case 4:
return "4th";
case 5:
return "5th";
default:
return "???";
}
}
}
Can this be done using data annotations such as something like
[Display(Name="CallFrom")
[TypeConverter(Type=".....")]
using a TypeConverter? I've googled everywhere but can't find anything. I want to take full advantage of EF and scrap my view models.
Thanks for your help.
displaytemplate
Ordinals.cshtml
and then simply decorate the property with[UIHint("Ordinals")]
. Also, "I want to take full advantage of EF and scrap my view models" is just folly. You entity classes should only focus on the needs of the database. Anything dealing with display or such should be on a view model. View models are virtually a necessity. If you try to just use entities, your app will be brittle and more error prone.