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

How to get ViewComponent as string in the controller?

$
0
0

I've searched around on how to get a ViewComponent as a string.

I found the method to do it in .cshtml razor like this:

var writer = new System.IO.StringWriter(new System.Text.StringBuilder());
(await Component.InvokeAsync(typeof(MyViewComp))).WriteTo(writer, HtmlEncoder.Default);
string viewCompString = writer.ToString();

But i cant do this in the backend, because the Component object is derived from razor that you can get in .cshtml, but not in the controller (i think).

Any help appreciated! :)


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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