2016-07-28 149 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" }) 

这是多么容易?!

相关问题