I managed to solve this by writing a custom view renderer.
The following question/answer helped me to solve this: Return View as String in .NET Core
in particular, Pharylon's answer.