2016-07-28 181 views
3

我看到媒體庫能夠將形狀附加到導航和操作。不過,我正在嘗試解決如何將操作形狀添加到操作中,以便可以將新按鈕添加到媒體庫以調用模塊中的操作。將自定義操作添加到Orchard CMS媒體庫

從媒體庫AdminController.cs:

// let other modules enhance the ui by providing custom navigation and actions 
var explorer = Services.ContentManager.New("MediaLibraryExplorer"); 
explorer.Weld(new MediaLibraryExplorerPart()); 

var explorerShape = Services.ContentManager.BuildDisplay(explorer); 

var viewModel = new MediaManagerIndexViewModel { 
    CustomActionsShapes = explorerShape.Actions, // <-- I need to have my shape that is rendered as a button in here 
}; 

還是有點綠色的果園,但感覺就像在我使用的形狀,並把他們的理解孔。我不認爲一個部分需要參與渲染按鈕的形狀,因爲沒有任何東西需要存儲。

回答

3

我設法解決了這個問題。首先在MediaLibraryExplorerPartDriver返回一個新的形狀爲MediaLibraryExplorerPart

public class MediaLibraryExplorerPartDriver : ContentPartDriver<MediaLibraryExplorerPart> { 
    protected override DriverResult Display(MediaLibraryExplorerPart part, string displayType, dynamic shapeHelper) { 
     return ContentShape("Parts_MediaLibraryExplorer_MyActionShape",() => shapeHelper.Parts_MediaLibraryExplorer_MyActionShape()); 
    } 
} 

然後將其放置在操作區

<Placement> 
    <Place Parts_MediaLibraryExplorer_MyActionShape="Actions:6" /> 
</Placement> 

然後創建模板(查看/配件/ MediaLibraryExplorer.MyActionShape.cshtml),用於與形狀按鈕來調用模塊控制器的動作:)

@Html.ActionLink(T("Click Me").Text, "Index", "Admin", new { area = "Orchard.MyModule" }, new { id = "click-me-link", @class = "button" }) 

這是多麼容易?!

相關問題