I am trying to render ViewComponent
to a string in a service in ASP.NET Core 3.0 (Pages).
I found two partial solutions to my problem, but both are for older pre 3.0 version and have some issues that I do not know how to resolve.
- First one is taken from GitHub Gist, but designed with controllers in mind and
NullView
was removed 3.0 (and is really hard to find any reference on it). - The second option is here, but fails one line 42 (no view is found). I believe that this is due to the changes made in .net core, where the views are now precompiled and the razor view engine therefore cannot find them.
I did some of my own experimenting, but could not get it working (I believe I am facing the same issue as the second solution I posted). I would appreciate any help regarding this matter on how to get it working. I've added my best attempt and a minimum project to GitHub, where Render is in the Service folder and in the Index.cshtml.cs is the call to the service.
Thanks!