Is it possible to specify the Display Template name when defining a property Type?
For example, I have some classes:
public interface IFoo {}
public class Foo : IFoo {}
public class Bar : IFoo {}
Then I have a Model:
public class MyModel{
IFoo IFooExample {get;set;}
}
Then I want to render IFooExample
in my View:
@model MyModel
@Html.DisplayFor(x => x.IFooExample)
Foo
and Bar
can share the same Display Template, ie ~/Views/Shared/DisplayTemplates/IFoo.cshtml
. How can I plug this logic into Mvc so that I don't have to either a) create Foo.cshtml
and Bar.cshtml
or b) from my View call DisplayFor
with an overload for the view (@Html.DisplayFor(x => x.IFooExample, "IFoo.cshtml")
).
I also don't want to decorate my Model with a UIHint attribute. I'd really like to specify the information on the definition of Foo
and Bar
:
[UIHint("IFoo.cshtml")]
public class Foo : IFoo{}
[UIHint("IFoo.cshtml")]
public class Bar : IFoo{}
But UIHint
s can't be applied at the class level. So is there another way to do this?