将自定义操作添加到Orchard CMS媒体库(Add custom action to Orchard CMS Media Library)

我看到媒体库能够将形状附加到导航和动作。 但是,我试图找出如何为动作添加动作形状,以便我可以在媒体库中添加一个新按钮来调用我的模块中的动作。

从媒体库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 };

Orchard仍然有点太绿,但感觉就像我对使用形状和放置它们的理解中的漏洞。 我不认为某个部分需要涉及渲染按钮的形状,因为没有任何东西需要存储?

I see that the Media Library has the ability to attach shapes to the navigation and actions. However I am trying to work out how to add an action shape to the actions so that I can have a new button added to the Media Library to invoke an action in my module.

From the Media Library 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 };

Still bit too green with Orchard, but feels like a hole in my understanding of using shapes and placing them. I don't think a part needs to be involved for a shape that renders button as there is nothing to be stored?

最满意答案

我设法解决了这个问题。 首先在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());
    }
}
 

然后放入Actions区域

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

然后使用按钮创建模板(Views / Parts / MediaLibraryExplorer.MyActionShape.cshtml)以调用模块控制器操作:)

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

这有多容易?!

I have managed to work this out. First return a new shape for the MediaLibraryExplorerPart in a MediaLibraryExplorerPartDriver

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

Then place in the Actions zone

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

Then create template (Views/Parts/MediaLibraryExplorer.MyActionShape.cshtml) for the shape with the button to invoke the module controller action :)

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

How easy was that?!

更多推荐