访问Orchard内容部件按钮(立即保存并发布)

时间:2013-09-13 09:59:07

标签: orchardcms orchardcms-1.6 orchardcms-1.7

我想根据某些条件禁用EDITOR模板中的Orchard Content Part按钮(立即保存并发布)(创建内容项时)。我能这样做吗?如何访问EDITOR视图中的按钮。

1 个答案:

答案 0 :(得分:0)

以下是示例,

从Controller Blog Module

中获取的Controller示例完全构建内容
public ActionResult Create() {
        if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Not allowed to create blogs")))
            return new HttpUnauthorizedResult();

        BlogPart blog = Services.ContentManager.New<BlogPart>("Blog");
        if (blog == null)
            return HttpNotFound();

        dynamic model = Services.ContentManager.BuildEditor(blog);
        // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
        return View((object)model);
    }

    [HttpPost, ActionName("Create")]
    public ActionResult CreatePOST() {
        if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't create blog")))
            return new HttpUnauthorizedResult();

        var blog = Services.ContentManager.New<BlogPart>("Blog");

        _contentManager.Create(blog, VersionOptions.Draft);
        dynamic model = _contentManager.UpdateEditor(blog, this);

        if (!ModelState.IsValid) {
            _transactionManager.Cancel();
            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return View((object)model);
        }

        _contentManager.Publish(blog.ContentItem);
        return Redirect(Url.BlogForAdmin(blog));
    }

BuidEditor为您完成工作。

您应该使用此template的替代版本,但请删除修改链接和发布链接。

注意,您需要一个自定义创建操作的路径,并且仪表板上的菜单链接可能会派上用场。