I am porting some code from Asp.net 4.7 to Asp.Net 5 Core. The code is using a foreach statement to loop through records. It is using the legacy "DisplayTemplates" functionality that matches types in the DisplayTemplates folder to polymorphically display different HTML for each item depending on the model. All classes are derived from the same base class.
In order to get it to work correctly in Asp.Net 5 Core, I had to change the code from:
@foreach (var token in Model.TokenGraph)
{
@Html.DisplayFor(t => token)
}
to:
@foreach (var token in Model.TokenGraph)
{
@Html.DisplayFor(t => token, token.GetType().Name)
}
... passing in the name of the type.
No problems problems and working correctly on my local machine.
The problem is when I publish the project to a remote server, the template used always defaults to the base class template.
Strangely enough, if I output the string returned by token.GetType().Name to the page, it matches the derived type name not the base type name.
Is this is a bug in .Net Core 5? If there is not a workaround, is there a better way to handle this in .Net 5?