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

How to get ViewComponent as string the the .cshtml view?

$
0
0

In Asp.Net vNEXT (the older version of Asp.Net Core), i could get the ViewComponent drawed as a string by calling Component.Invoke(XXX).ToString() or something like that very easy.

But now the current version Asp.net Core, the Invoke is removed and you can only call the InvokeAsync.

So i call the invoke async like this: 

@{
   string text = (await Component.InvokeAsync(typeof(Foo)).ToString();
}

then the "text" variable will become "Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewBuffer". And thats the name of a class or something, then the string that it was supposed to draw.

So... how do get the string in the newest version?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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