1

我正在按照 Kevin Kuebler 的 Pluralsight 教程在 Orchard 1.4 中构建一个自定义模块。我相信我拥有所需的一切,但是当我启用我的模块并尝试添加新文章(我的自定义内容类型)时,我没有看到我的自定义内容部分的字段。我按照教程从头开始重建了很多次,但一直卡在同一个地方。我已经用谷歌搜索了答案,但从我所看到的情况来看,我已经准备好了我需要的一切。以下是我的代码片段。

迁移.cs

using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
using Orchard.ContentManagement.MetaData;

    namespace Northern.Articles {
    public class Migrations : DataMigrationImpl {

        public int Create() {

            ContentDefinitionManager.AlterTypeDefinition("Article", builder =>
                builder.WithPart("CommonPart")
                .WithPart("TitlePart")
                .WithPart("AutoroutePart")
                .WithPart("BodyPart", partBuilder =>
                    partBuilder.WithSetting("BodyTypePartSettings.Flavor","Text")
                    )
                .Creatable()
                .Draftable()
                );

            return 1;
        }

        public int UpdateFrom1() {

            SchemaBuilder.CreateTable("ArticlePartRecord", table =>
                table.ContentPartRecord()
                .Column<int>("ArticleID")
                .Column<string>("PrimaryImage", col => col.WithLength(300))
                .Column<string>("ThumbImage", col => col.WithLength(300))
                .Column<bool>("IsFeatured"));

            ContentDefinitionManager.AlterTypeDefinition("Article", builder =>
                builder.WithPart("ArticlePart"));

            return 2;
        }
    }
}

文章PartRecord.cs

using Orchard.ContentManagement.Records;
namespace Northern.Articles.Models
{
    public class ArticlePartRecord : ContentPartRecord
    {
        public virtual int ArticleID { get; set; }
        public virtual string PrimaryImage { get; set; }
        public virtual string ThumbImage { get; set; }        
        public virtual bool IsFeatured { get; set; }
    }
}

文章Part.cs

using Orchard.ContentManagement;

namespace Northern.Articles.Models
{
    public class ArticlePart : ContentPart<ArticlePartRecord>
    {
        public int ArticleID {
            get { return Record.ArticleID; }
            set { Record.ArticleID = value; }
        }
        public string PrimaryImage
        {
            get { return Record.PrimaryImage; }
            set { Record.PrimaryImage = value; }
        }
        public string ThumbImage
        {
            get { return Record.ThumbImage; }
            set { Record.ThumbImage = value; }
        }
        public bool IsFeatured
        {
            get { return Record.IsFeatured; }
            set { Record.IsFeatured = value; }
        }
    }
}

文章PartDriver.cs

using Orchard.ContentManagement.Drivers;
using Northern.Articles.Models;
using Orchard.ContentManagement;

namespace Northern.Articles.Drivers
{
    class ArticlePartDriver : ContentPartDriver<ArticlePart>
    {
        protected override string Prefix
        {
            get
            {
                return "Article";
            }
        }

        //GET
        protected override DriverResult Editor(ArticlePart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Article_Edit", () =>
                shapeHelper.EditorTemplate(TemplateName: "Parts/Article", Model: part, Prefix: Prefix));
        }

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

文章处理程序.cs

using Orchard.ContentManagement.Handlers;
using Orchard.Data;
using Northern.Articles.Models;

namespace Northern.Articles.Handler
{
    public class ArticleHandler : ContentHandler
    {
        public ArticleHandler(IRepository<ArticlePartRecord> articlePartRepository)
        {
            Filters.Add(StorageFilter.For(articlePartRepository));
        }
    }
}

视图\EditorTemplates\Parts\Article.cshtml

@model Northern.Articles.Models.ArticlePart

<fieldset>
    <legend>@T("Article Details")</legend>
    @Html.LabelFor(m => m.ArticleID, T("Article ID"))
    @Html.TextBoxFor(m => m.ArticleID)
    @Html.LabelFor(m => m.PrimaryImage, T("Primary Image"))
    @Html.TextBoxFor(m => m.PrimaryImage)
    @Html.LabelFor(m => m.ThumbImage, T("Thumbnail Image"))
    @Html.TextBoxFor(m => m.ThumbImage)
    @Html.LabelFor(m => m.IsFeatured, T("Is Featured"))
    @Html.CheckBoxFor(m => m.IsFeatured);
</fieldset> 

安置信息

<?xml version="1.0" encoding="utf-8" ?>
<Placement>
  <Place Parts_Article_Edit="Content:10"/>
</Placement>

模块正确加载并在数据库中创建表,我只是在添加/编辑文章时没有看到这些字段。

看到我看不到的东西的任何帮助将不胜感激。

4

1 回答 1

1

在我看来,你已经准备好了一切。我在查看代码时注意到的一件事是您在 ArticlePartDriver 类上没有公共访问修饰符。如果您不将它们指定为公共,则类在 C# 中默认是内部的。我的猜测是 Orchard 无法创建 Driver 类,因为它不是公开的。

于 2012-05-08T01:54:05.500 回答