Rendering Partials in .Net Core but get an error output on screen

A short blog today - this is more a reminder for future self than anything else. 

If rendering a partial view and perhaps upgrading a site from .Net Framework to .Net Core. You might see this message output in to your rendered site - 

System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Html.IHtmlContent]

This is likely to be because you are replacing

@Html.Partial("yourPathToYourPartialView")

With

@Html.PartialAsync("yourPathToYourPartialView")

and you are almost correct, but you need to add await in from of the Html.

So you should have

@await Html.PartialAsync("yourPathToYourPartialView")

This removes the erronous output and displays your partial.

Published on : 17 October 2024