What's the Model in declared in your view? The abstract or child?
It uses reflection to read the attribute based on the model declared so:
@model PostBase
@Html.DisplayFor(m => m.Body)
Will work differently to
@model MessagePost
@Html.DisplayFor(m => m.Body)
the first of these will apply the [Required]
only. It's bound to a PostBase
model (doesn't know or care what the child class), so when it reflects the PostBase
class; this only has [Required]
on that property. So it never looks for the MultilineText.cshtml
, why would it? It's not got MultilineText
on it.
The second one will apply [StringLength(500), DataType(DataType.MultilineText)]
and [Required]
. The attributes are combined for inherited classes so when it reflects the class it'll see both attributes.
This view should use the template as required. I'm guessing this doesn't work for you though as I'm presuming the inheritance is there for a reason?