Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore 7.1 MVC Rendering Helper passing variables

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 })
like image 385
Komainu85 Avatar asked Aug 04 '15 08:08

Komainu85


1 Answers

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?

like image 82
Shane Avatar answered Oct 21 '22 18:10

Shane