在Orchard中创建内容项时,不显示内容部分编辑视图

时间:2012-04-17 12:34:16

标签: asp.net orchardcms

我创建了一个内容部分,然后将其添加到Orchard中的内容类型中。但是当我尝试创建该类型的内容项时,不会显示该部件属性的字段。我正在寻找可能出现问题的建议。

UPD:相关代码:

using JetBrains.Annotations;
using ArealAds.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using ArealAds.Models;
using ArealAds.Services;
using ArealAds.ViewModels;

namespace ArealAds.Drivers {
    [UsedImplicitly]
    public class AdDriver : ContentPartDriver<AdPart> {
        private readonly IAdService _adService;

        public AdDriver (IAdService adService)
        {
            _adService = adService;
        }

        protected override string Prefix {
            get { return "AdPart"; }
        }

        protected override DriverResult Display(
            AdPart part, string displayType, dynamic shapeHelper) {

            return ContentShape("Parts_Ad", () => shapeHelper.Parts_Ad(
                Title: part.Title,
                Url: part.Url,
                Email: part.Email,
                Phone1: part.Phone1,
                Phone2: part.Phone2,
                AreaName: part.AreaRecord.Name,
                AreaId: part.AreaRecord.Id,
                DistrictName: part.DistrictRecord.Name,
                DistrictId: part.DistrictRecord.Id,
                AllDistricts: part.AllDistricts));
        }

        //GET
        protected override DriverResult Editor(
            AdPart part, dynamic shapeHelper) {

            return ContentShape("Parts_Ad_Edit",
                () => shapeHelper.EditorTemplate(
                    TemplateName: "Parts/Ad",
                    Model: BuildEditorViewModel(part),
                    Prefix: Prefix));
        }
        //POST
        protected override DriverResult Editor(
            AdPart part,
            IUpdateModel updater,
            dynamic shapeHelper) {

            var model = new EditAdViewModel();
            updater.TryUpdateModel(model, Prefix, null, null);

            if (part.ContentItem.Id != 0) {
                _adService.Update(
                    part.ContentItem, model);
            }

            return Editor(part, shapeHelper);
        }

        private EditAdViewModel BuildEditorViewModel(AdPart part) {
            var avm = new EditAdViewModel {
                Title = part.Title,
                Url = part.Url,
                Email = part.Email,
                Phone1 = part.Phone1,
                Phone2 = part.Phone2,
                AllDistricts = part.AllDistricts,
                Areas = _adService.GetAreas(),
                Districts = _adService.GetDistricts()
            };
            if (part.AreaRecord != null) {
                avm.AreaName = part.AreaRecord.Name;
                avm.AreaId = part.AreaRecord.Id;
            }
            if (part.DistrictRecord != null) {
                avm.DistrictName = part.DistrictRecord.Name;
                avm.DistrictId = part.DistrictRecord.Id;
            }
            return avm;
        }
    }
}

using System.ComponentModel.DataAnnotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;

namespace ArealAds.Models {
    public class AdRecord : ContentPartRecord {
        public virtual string Title { get; set; }
        public virtual string Url { get; set; }
        public virtual string Email { get; set; }
        public virtual string Phone1 { get; set; }
        public virtual string Phone2 { get; set; }
        public virtual AreaRecord AreaRecord { get; set; }
        public virtual DistrictRecord DistrictRecord { get; set; }
        public virtual bool AllDistricts { get; set; }
    }

    public class AdPart : ContentPart<AdRecord> {
        [Required]
        public string Title {
            get { return Record.Title; }
            set { Record.Title = value; }
        }

        public string Url {
            get { return Record.Url; }
            set { Record.Url = value; }
        }

        public string Email {
            get { return Record.Email; }
            set { Record.Email = value; }
        }

        public string Phone1 {
            get { return Record.Phone1; }
            set { Record.Phone1 = value; }
        }

        public string Phone2 {
            get { return Record.Phone2; }
            set { Record.Phone2 = value; }
        }

        public AreaRecord AreaRecord {
            get { return Record.AreaRecord; }
            set { Record.AreaRecord = value; }
        }

        public DistrictRecord DistrictRecord {
            get { return Record.DistrictRecord; }
            set { Record.DistrictRecord = value; }
        }

        [Required]
        public bool AllDistricts {
            get { return Record.AllDistricts; }
            set { Record.AllDistricts = value; }
        }
    }
}


@model ArealAds.ViewModels.EditAdViewModel

<fieldset>
  <legend>Area Fields</legend>

  <div class="editor-label">
    @Html.LabelFor(model => model.Title)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Title)
    @Html.ValidationMessageFor(model => model.Title)
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.Url)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Url)
    @Html.ValidationMessageFor(model => model.Url)
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.Email)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Email)
    @Html.ValidationMessageFor(model => model.Email)
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.Phone1)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Phone1)
    @Html.ValidationMessageFor(model => model.Phone1)
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.Phone2)
  </div>
  <div class="editor-field">
    @Html.TextBoxFor(model => model.Phone2)
    @Html.ValidationMessageFor(model => model.Phone2)
  </div>

  <div class="editor-label">
    @Html.LabelFor(model => model.AllDistricts)
  </div>
  <div class="editor-field">
    @Html.CheckBoxFor(model => model.AllDistricts)
    @Html.ValidationMessageFor(model => model.AllDistricts)
  </div>

  <table>
  <tr>
  <td>
  <div class="editor-label">
    @Html.LabelFor(model => model.AreaId)
  </div>
  <div class="editor-field">
    @Html.DropDownListFor(model => model.AreaId,
                          Model.Areas.Select(s => new SelectListItem {
                              Selected = s.Id == Model.AreaId,
                              Text = s.Name,
                              Value = s.Id.ToString()
                          }),
                      "Выберите район...")
    @Html.ValidationMessageFor(model => model.AreaId)
  </div>
  </td>
  <td>или</td>
  <td>
  <div class="editor-label">
    @Html.LabelFor(model => model.DistrictId)
  </div>
  <div class="editor-field">
    @Html.DropDownListFor(model => model.DistrictId,
                          Model.Districts.Select(s => new SelectListItem {
                              Selected = s.Id == Model.DistrictId,
                              Text = s.Name,
                              Value = s.Id.ToString()
                          }),
                      "Выберите округ...")
    @Html.ValidationMessageFor(model => model.DistrictId)
  </div>
  </td>
  </tr>
  </table>

</fieldset>


            SchemaBuilder.CreateTable("AdRecord", table => table
                .ContentPartRecord()
                .Column<string>("Title")
                .Column<string>("Url")
                .Column<string>("Email")
                .Column<string>("Phone1")
                .Column<string>("Phone2")
                .Column<int>("AreaRecord_Id")
                .Column<int>("DistrictRecord_Id")
                .Column<bool>("AllDistricts")
            );

            ContentDefinitionManager.AlterPartDefinition(
                typeof(AdPart).Name, cfg => cfg.Attachable());

            ContentDefinitionManager.AlterTypeDefinition(
                "ArealAds_Ad", cfg => cfg
                .WithPart("CommonPart")
                .WithPart("AdPart")
                .Creatable()
            );

1 个答案:

答案 0 :(得分:5)

您可能错过了placement.info中的条目。

将此添加到模块中的placement.info文件中(而不是yoru主题的placement.info,因为当您在仪表板中时主题不活动):

`<Place Parts_Ad_Edit="Content:1" />`
相关问题