【问题标题】:How to render a ShapeTemplate without a contentitem?如何在没有内容项的情况下呈现 ShapeTemplate?
【发布时间】:2017-06-27 09:57:50
【问题描述】:

我是果园新手,由于 MVCSHD 模型,我的大脑正在燃烧 (模型视图控制器形状处理程序驱动程序)

来自果园文档:

形状是动态数据模型,它使用形状模板以您希望的方式使数据对用户可见。形状模板是用于渲染形状的标记片段。形状的示例包括菜单、菜单项、内容项、文档和消息。

我想显示一个形状模板并向视图提供一个模型,该模型不是 ContentPart 并且没有 ContentItem。

因为我想在控制器中创建这个模型(或者如果我最终得到这个工作,则在以后的驱动程序中)。 模型的内容是动态创建的。

在控制器中这不起作用:

        TestThingie testThingie = new TestThingie (5);
        _orchardServices.ContentManager.BuildDisplay(testThingie,"Summary");

因为 testTingie 没有 contentItem... 有没有其他方法可以显示带有模型的 shapeTemplate?我在这里错过了什么?

是我自己还是有点不可能从文档中获得有关所有这些东西将如何工作的更多信息?

【问题讨论】:

    标签: model-view-controller orchardcms


    【解决方案1】:

    BuildDisplay 方法用于制作给定内容项的显示形状。您没有内容项,因此无法使用该方法。

    你可以做的是使用动态Display:

    public ActionResult MyAction() {
        TestThingie testThingie = new TestThingie(5);
    
        return View(myShape);
    }
    

    然后在您的 Views/MyControllerName/MyAction.cshtml 中:

    @Display.MyShape(Thingie: Model.TestThingie)
    

    在你的 MyShape.cshtml 中:

    @{
        TestThingie thingie = Model.Thingie;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-02
      • 2012-04-09
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 2014-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多