Okay, I have been looking for a resolution for this simple task all day.
I have an mvc model class which has a BIC property and a NationalNumber property. Bother are string values. I want to use a DisplayFor helper to render the property on the view BUT, with a formatting applied.
for completeness: the formatting for the NationalNumber is '00.00.00-000.00' , the formatting for BIC is AAAA BB CC
I tried annotating my properties with a DisplayFormat Attribute, but that only seems to work with DateTimes, numeric values, etc,..
[DisplayFormat(DataFormatString = "{0:##.##.##-###.##}")]
Then I looked at creating a custom DisplayFormat attribute, but that also works with patterns that apply to DateTimes, numeric values, etc.. You still need to suppy a DataFormatString value in the constructor of your custom attribute. But the filter does not seem to work with strings!
For the moment I ended up doing the markup clientSide(with a mask plugin) but that's not really what I want!
To summarize: I want to use @Html.DisplayFor(x=>x.BicNumber) and have it rendered with a custom formatting, preferrably annotaded on my viewmodel, with BicNumber being a string.
Thanks in advance
DisplayFormatnever worked for strings in the first place.string.Format("{0:##.##.##-###.##}", what ever value needs to be formatted)