1

我正在学习 Orchard CMS 并尝试创建自定义类型。我遵循了各种教程,创建了模型类和 Migration.cs,并且能够看到我的部分显示在 Orchard 上列出的内容部分下。

在此处输入图像描述

然后我添加了驱动程序、处理程序、视图和placement.info。但是,当我创建或查看包含我的零件的项目时,我无法看到我的新零件的字段——该项目在我的零件字段应该存在的地方是空的。

在此处输入图像描述

这是我的视图/零件/Event.cshtml:

@using Orchard.ContentManagement.ViewModels
@using Orchard.ContentManagement
@using Orchard.Core.Common.Models
<div class="event-container">
    <div class="event-text">
        <p>Event Name: @Model.EventName</p>
    </div>
    <div>
        <p>Event ID: @Model.EventID</p>
    </div>
    <div>
        <p>Description: @Model.Description</p>
    </div>
</div>

这是我的视图/EditorTemplates/Event.cshtml:

@using System.Web.Mvc.Html
@using Orchard.Event.Models
@model Orchard.Event.Models.EventPart
<fieldset>
    <legend>@T("Event Fields")</legend>

    <div class="editor-field">
        @Html.LabelFor(x => x.EventName, T("Event Name"))
        @Html.EditorFor(x => x.EventName)
        @Html.ValidationMessageFor(x => x.EventName)
    </div>
    <div class="hint">@T("Enter the Event Name")</div>

    <div class="editor-field">
        @Html.LabelFor(x => x.EventID, T("Event ID"))
        @Html.EditorFor(x => x.EventID)
        @Html.ValidationMessageFor(x => x.EventID)
    </div>
    <div class="hint">@T("Enter the Event ID")</div>

     <div class="editor-field">
        @Html.LabelFor(x => x.Description, T("Description"))
        @Html.EditorFor(x => x.Description)
       @Html.ValidationMessageFor(x => x.Description)
    </div>
    <div class="hint">@T("Enter the Description")</div>

</fieldset>

司机:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Handlers;
using Orchard.Event.Models;

namespace Orchard.Event.Drivers
{
    public class EventPartDriver : ContentPartDriver<EventPart>
    {
        protected override string Prefix
        {
            get
            { return "Event"; }
        }

        protected override DriverResult Editor(EventPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Event_Edit", () => shapeHelper
                .EditorTemplate(TemplateName: "Parts/Event", Model: part,     Prefix: Prefix));
    }

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

    protected override DriverResult Display(EventPart part, string displayType, dynamic shapeHelper)
    {
        return ContentShape("Parts_Event",
            () => shapeHelper.Parts_Event(
                EventName: part.EventName,
                EventID: part.EventID,
                Description: part.Description
                ));
    }
}

}

安置信息:

<Placement>
<place Parts_Event="Content:10"/>
<place Parts_Event_Edit="Content:7.5"/>
</Placement>

任何想法将不胜感激;我已经将这些与教程进行了比较,纸上的一切似乎都是正确的。

4

1 回答 1

0

有两件事是错误的:

  1. 您的编辑器视图应该在Views/EditorTemplates/Parts评论中建议的 Bertrand
  2. 您尚未添加该部分的处理程序 - 在此处查看更多信息 - http://docs.orchardproject.net/Documentation/Creating-a-module-with-a-simple-text-editor#AddingaHandler
于 2012-12-07T08:09:47.667 回答