I have a service which generates email messages and returns them a string. However, I have a view component which I usually call from my views and append the result with an already present string:
string result = @await Component.InvokeAsync("Widget", new { widgetZone = "stock_levels_summary_cart_price", additionalData = product.Id })
sb.AppendLine($"<td style=\"padding: 0.6em 0.4em;text-align: center;\">{result}</td>");
How can I call this view component in my service and pass the result into a string variable which I can use in my email message service?
I was able to implement this by creating a partial view for the view component.
In the partial view, I declared my view component:
In my controller, I created an action as follows:
Then I implemented a service to render the partial view content and return the result:
Then, to load the partial view that was created from a view component, I executed the method as follows: