【问题标题】:Orchard custom module showing blank "Create" page显示空白“创建”页面的果园自定义模块
【发布时间】:2012-04-14 16:52:42
【问题描述】:

我在 this wonderful guide 之后为 Orchard 创建了一个自定义模块。

我创建了一个名为 BarberAdminController 的控制器,如下所示:

[Admin]
public class BarberAdminController : Controller
{
    ...

    public BarberAdminController(IOrchardServices services, IRepository<BarberPart> repository)
    {
        _repository = repository;
        _services = services;
    }

    ... 

    public ActionResult Create()
    {
        var barber = _services.ContentManager.New(typeof(BarberPart).ToString());

        dynamic model = _services.ContentManager.BuildEditor(barber);

        return View(model);
    } 
}

查看:

@{ Layout.Title = T("New Barber").ToString(); }

@using (Html.BeginFormAntiForgeryPost()) {
    @Html.ValidationSummary()
    // Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
    @Display(Model)
}

单击管理菜单中的链接以创建理发师后,我得到一个空白页面,其中只有一个“保存”按钮。 (网址:/Admin/BarberShop/Barbers/Create)

有人知道我做错了什么吗?

我已经设置了路由和管理链接,它们似乎工作正常。我尽可能地按照指南正确地为 BarberPart 创建驱动程序和处理程序。包括到 Migration.cs 文件数据库架构。

任何帮助都会很棒!

【问题讨论】:

  • 可能缺少展示位置?

标签: asp.net asp.net-mvc-3 module orchardcms


【解决方案1】:

我想通了。

我需要为 BarberPart 定义内容部分和内容类型。在 Migrations.cs 中,执行:

ContentDefinitionManager.AlterPartDefinition(typeof(BarberPart).Name, p => p
            .Attachable(false));
ContentDefinitionManager.AlterTypeDefinition("Barber", t => t
            .WithPart(typeof(BarberPart).Name));

在Controller的“Create”方法中,替换:

var barber = _services.ContentManager.New(typeof(BarberPart).ToString());

与:

BarberPart barber = _services.ContentManager.New<BarberPart>("Barber");

确保您有这样的 Drivers/BarberDriver.cs 文件:

public class BarberDriver : ContentPartDriver<BarberPart> 
{
    protected override DriverResult Editor(BarberPart part, dynamic shapeHelper)
    {
        return ContentShape("Parts_Barber_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/Barber", Model: part, Prefix: Prefix));
    }

    protected override DriverResult Editor(BarberPart part, IUpdateModel updater, dynamic shapeHelper)
    {
        updater.TryUpdateModel(part, Prefix, null, null);
        return Editor(part, shapeHelper);
    }
}

确保在 /Views/EditorTemplates/Parts/Barber.cshtml 中有一个部分编辑模板,如下所示:

@model SDKU.Barbr.Models.BarberPart

<fieldset>
    @Html.EditorFor(model => model.SomePropertyName)
    etc...
</fieldset>

【讨论】:

    猜你喜欢
    • 2022-07-27
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多