I have a view component for displaying lists of products. The component is called with model and data and is more or less just layouting the products. This is reused from multiple views.
I would like to add the option to "dynamic" include a call to the viewcomponent from a controller. One example would be to store a merge code in the database, something like |:ShowProductsOnSale:| When this string is found, I would like to make a call to the ViewComponent, get the html back to the controller and replace |:ShowProductsOnSale:| with the html. Is it possible at all? Or might there be a better solution that I havn't thought of?
if (content.IndexOf("|:ShowProductsOnSale:|") > 0)
{
// Somehow get content of ViewComponent
var html = _some_content;
content = content.Replace("|:ShowProductsOnSale:|", html);
}
** EDIT ** The "dynamic" load that I need, is for users to be able to add the list of products on sale, where ever they want.
I cannot call the viewcomponent directly from the controller, because i don't know where to use it. A user might be creating a page with some content (posting the content including html to a database) The content might include something like:
Here is a list of our product currently on sale<br>|:ShowProductsOnSale:|<br>
Click on a product above to buy it.
I need some way to replace the |:ShowProductsOnSale:| with the content created by the viewcompnent. I also need to make the replace in the controller, because i need to send data to the viewcomponent