The
Html.Partial
method returns a
ViewBuffer
instance. That class does not override
ToString
, so the result of that method will be the full class name.
If you want to render the content to a string, you need to use
the WriteTo
method[
^].
var replacements = new Dictionary<string, IHtmlContent>
{
["{partv _AllPages}"] = Html.Partial("_AllPages"),
["{partv _AllPosts}"] = Html.Partial("_AllPosts"),
};
string output = input;
foreach (var pair in replacements)
{
if (!output.Contains(pair.Key)) continue;
string replacement;
using (var writer = new StringWriter())
{
pair.Value.WriteTo(writer, HtmlEncoder.Default);
replacement = writer.ToString();
}
output = output.Replace(pair.Key, replacement);
}
NB: Calling
HttpUtility.HtmlDecode
on the output is almost certainly the wrong thing to do.
I suspect you might be better served using something like this:
Back to Basics: Rendering Razor Views to String in ASP.NET Core - Rick Strahl's Web Log[
^]