0

我想根据某些条件禁用编辑器模板(创建内容项时)中的果园内容部分按钮(立即保存和发布)。我可以这样做吗?如何访问 EDITOR 视图中的按钮。

4

1 回答 1

0

这里有例子,

完全从控制器示例构建内容,取自博客模块

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 为您完成工作。

您应该使用此模板的替代版本,但删除编辑链接和发布链接。

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

于 2013-09-22T13:40:48.677 回答