自定义Orchard CMS 1.4模块编辑器形状不渲染

时间:2012-05-07 16:54:32

标签: asp.net-mvc-3 orchardcms

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

Migrations.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;
        }
    }
}

ArticlePartRecord.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; }
    }
}

ArticlePart.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; }
        }
    }
}

ArticlePartDriver.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);
        }
    }
}

ArticleHandler.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 \零件\ 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> 

Placement.info

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

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

任何看到我看不到的帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:1)

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