Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

MVC ViewComponents, InvokeAsync result not sent to output stream

$
0
0

Since RC2 forced the use of InvokeAsync I can't get output into the page without forcing it there myself.

If I create a new ASP .NET project and add a view component, then reference it in a razor page thus:

@{ await Component.InvokeAsync<ComponentTestViewComponent>(); }

The code is executed, the viewmodel is created etc. and everything executes as it should, but the output does not appear in the page.  

However if I use the result object to force output into the page, thus:

@{ Component.InvokeAsync<ComponentTestViewComponent>().Result.WriteTo(Output, System.Text.Encodings.Web.HtmlEncoder.Default); }

then it all renders correctly.

None of the examples about RC2 seem to need this hack, so I can only assume I've done something wrong somewhere or am 'missing the point' about ViewComponents?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>