I created a custom module for Orchard following this wonderful guide.
I have created a controller called BarberAdminController as follows:
[Admin]
public class BarberAdminController : Controller
{
...
public BarberAdminController(IOrchardServices services, IRepository<BarberPart> repository)
{
_repository = repository;
_services = services;
}
...
public ActionResult Create()
{
var barber = _services.ContentManager.New(typeof(BarberPart).ToString());
dynamic model = _services.ContentManager.BuildEditor(barber);
return View(model);
}
}
View:
@{ Layout.Title = T("New Barber").ToString(); }
@using (Html.BeginFormAntiForgeryPost()) {
@Html.ValidationSummary()
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
@Display(Model)
}
Upon clicking the link from the admin menu to create a Barber, I get a blank page with nothing but a “Save” button. (URL: /Admin/BarberShop/Barbers/Create)
Does anyone know what I might be doing wrong?
I’ve set up the routes and admin links and they seem to work fine. I followed the guide as closely as I could on creating the Drivers and Handlers for BarberPart correctly. Including down to the Migration.cs file database schema.
Any help would be great!
I figured it out.
I needed to define a Content Part and Content Type for BarberPart. In Migrations.cs, do:
In the “Create” method of the Controller, replace:
with:
Make sure that you have a Drivers/BarberDriver.cs file as such:
Be sure to have a part edit template located in /Views/EditorTemplates/Parts/Barber.cshtml that looks like this: