在 sitecore 视图渲染中传递 Glass 模型

Passing Glass Model in sitecore view rendering

我们有两个继承自不同 Glass 型号的玻璃视图,它们都可以单独使用。

现在,我们要将一个视图插入到另一个视图中。所以我尝试使用下面的代码:

var model = new SitecoreContext().GetItem<IOurGlassModel>(path);
if (model != null)
{
    @Html.Sitecore().ViewRendering("/Views/path/Banner.cshtml", new { Model = model })
}

最后出现以下错误消息:

Server Error in '/' Application. Could not locate item containing model definition. Model path: Castle.Proxies.IOurGlassModelProxy_1

如果您需要完整的堆栈跟踪,请告诉我。

如有任何建议,我们将不胜感激。

使用这个代替:

@Html.Partial("/Views/path/Banner.cshtml", model)

重点是@Html.Sitecore()。ViewRendering 将重新调用 Sitecore 管道并从头开始渲染您的组件。另一方面,使用@Html.Partial 将使用相同的执行渲染部分视图。

查看此问题以了解有关两种方法之间差异的更多详细信息: