如何在orchard cms中以编程方式创建投影小部件?

时间:2015-02-14 09:29:38

标签: widget orchardcms projection orchardcms-1.8

我在我的模块中使用以下代码创建了一个查询:

var myName = "something" 
var theQuery = _contentManager.Create("Query"); 
theQuery.As<TitlePart>().Title = myName + "Query"; 
var filterGroupRecord = new FilterGroupRecord(); 
var filterRecord = new FilterRecord() 
{
    Category = "Content", Type = "ContentTypes", 
    Description = myName , Position = 1, 
    State = "<Form><Description>" + myName 
          + "</Description>    <ContentTypes>" + myName + "</ContentTypes></Form>"
}; 
filterGroupRecord.Filters.Insert(0, filterRecord); 
theQuery.As<QueryPart>().FilterGroups.Clear(); 
theQuery.As<QueryPart>().FilterGroups.Insert(0, filterGroupRecord); 

我知道要在代码下面创建一个投影小部件:

var theProjectionWidget = _contentManager.Create("ProjectionWidget"); 
theProjectionWidget .As<WidgetPart>().Title = myName + "ProjectionWidget"; 
theProjectionWidget .As<WidgetPart>().RenderTitle = false; 
theProjectionWidget .As<WidgetPart>().Zone = "Content"; 
theProjectionWidget .As<WidgetPart>().Position = "1"; 
theProjectionWidget .As<WidgetPart>().LayerPart.Name = myName; 

但我不知道如何将上述查询分配给这个新的投影窗口小部件。 如何将查询ID分配给ProjectionPart.QueryLayoutRecordId ??? !!

我将不胜感激任何帮助。

这些是codeproject&amp; amp; codeplex:

http://www.codeproject.com/Questions/876128/How-to-create-a-projection-widget-programmatically

https://orchard.codeplex.com/discussions/580735

1 个答案:

答案 0 :(得分:0)

经过一些代码和调试的摔跤后,我找到了解决问题的方法。 有问题的人都可以使用这段代码:

theProjectionWidget.As<ProjectionPart>().Record.QueryPartRecord = new QueryPartRecord(){

            ContentItemRecord = theQuery.As<QueryPart>().ContentItem.Record,
            FilterGroups = theQuery.As<QueryPart>().FilterGroups,
            Id = theQuery.As<QueryPart>().Id,
            Layouts = theQuery.As<QueryPart>().Layouts,
            SortCriteria = theQuery.As<QueryPart>().SortCriteria

        };
相关问题