Orchard CMS - 无法查看自定义类型的字段

时间:2012-12-06 23:49:00

标签: content-management-system orchardcms

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

enter image description here

然后我添加了一个驱动程序,处理程序,视图和placement.info。但是,当我创建或查看包含我的部分的项目时,我无法看到我的新部分的字段 - 项目在我的部分字段应该是空的。

enter image description here

这是我的Views / Parts / 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>

这是我的Views / 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.info:

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

任何想法都会受到高度赞赏;我将这些与教程进行了比较,一切似乎都是正确的。

1 个答案:

答案 0 :(得分:0)

有两件事是错的:

  1. 您的编辑器视图应位于Views/EditorTemplates/Parts中,正如Bertrand在评论中所建议的那样
  2. 您尚未添加该部件的处理程序 - 请在此处查看更多信息 - http://docs.orchardproject.net/Documentation/Creating-a-module-with-a-simple-text-editor#AddingaHandler