I'm trying to add a view returned from a controller into my view statically. In standard MVC I would do something like the below.
@{Html.RenderAction("Product", "ProductListing", new {productId = product.ItemId});}
Here is my controller
[System.Web.Http.HttpGet]
public ActionResult Product(ID productId)
{
var product= _productRepositorty.GetProduct(productId);
return View("~/Views/Product/ProductDetails.cshtml", product);
}
So using the Sitecore rendering helper i have the below, where the ID is the rendering item within Sitecore pointing at the controller and action as above. However I am unable to pass through the productId as a parameter into the Product action (the productId is always null). Is this the correct way of passing a variable to another action?
@Html.Sitecore().Rendering("{AA6C2188-1897-4577-BE0A-25DD2BBA8AF1}", new { productId = product.ItemId })
As far as I'm aware this syntax is not supported for passing parameters to insert into the action.
The parameters you specify are put into the rendering.Properties
collection.
Would it be possible to rewrite the action signature and use the RenderingContext.Current.Rendering.Properties
inside to read the value?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With