使用动态数据源的 Sitecore Viewrendering
Sitecore Viewrendering with dynamic datasource
您好,我有简单的视图渲染(例如带有标题和 body)。
虽然当我在演示布局中为我的呈现控件提供数据源时它工作得很好 - 我想知道我是否可以通过代码来完成 - 即通过代码定义数据数据源。
目前我有这样的东西可以正常工作:
@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<sample.Web.Models.sampleclass>
@if (Model != null)
{
<div>
@Model.Title
</div>
}
寻找类似下面的东西,我可以在其中定义我的数据源或项目
@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<sample.Web.Models.sampleclass>
@datasource = Sitecore.context.database.getitem("some different path or id");
@if (Model != null)
{
<div>
@Model.Title
</div>
}
你可以这样使用:
@{
var dynamicDatasource = new SitecoreContext().GetItem<sampleclass>(other_item_id)
}
@if (dynamicDatasource != null)
{
<div>
@Html.Glass().Editable(dynamicDatasource, d => d.Title)
</div>
}
您好,我有简单的视图渲染(例如带有标题和 body)。 虽然当我在演示布局中为我的呈现控件提供数据源时它工作得很好 - 我想知道我是否可以通过代码来完成 - 即通过代码定义数据数据源。
目前我有这样的东西可以正常工作:
@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<sample.Web.Models.sampleclass>
@if (Model != null)
{
<div>
@Model.Title
</div>
}
寻找类似下面的东西,我可以在其中定义我的数据源或项目
@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<sample.Web.Models.sampleclass>
@datasource = Sitecore.context.database.getitem("some different path or id");
@if (Model != null)
{
<div>
@Model.Title
</div>
}
你可以这样使用:
@{
var dynamicDatasource = new SitecoreContext().GetItem<sampleclass>(other_item_id)
}
@if (dynamicDatasource != null)
{
<div>
@Html.Glass().Editable(dynamicDatasource, d => d.Title)
</div>
}