I am learning Orchard CMS and tried to create a custom type. I followed various tutorials, creating the Model classes and Migration.cs, and was able to see my part show up under the listed Content Parts on Orchard.
I then added a driver, handler, views, and placement.info. However, I am not able to see the fields of my new part when I create or view an item that contains my part -- the item is empty where my part's fields should be.
Here is my 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>
Here is my 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>
Driver:
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>
any ideas would be greatly appreciated; I've compared these with the tutorials and everything seems to be correct on paper.