I'm working on a module where I need to store my settings. I'm storing them in a content part called ContactUsSettingsPart.
I've got an Admin controller that is linked from the admin menu. Here is the important part of my Edit settings action method:
var contact = _contactUsService.Get();
if (contact == null) contact = Services.ContentManager.New<ContactUsSettingsPart>(typeof(ContactUsSettingsPart).Name);
var model = Services.ContentManager.BuildEditor(contact);
This is based on the blog admin controller. I'm having trouble with the second line. I needed this because I couldn't pass null to BuildEditor, and contact is null before a user has filled out the form for the first time.
ContentManager.New<ContactUsSettingsPart> throws an InvalidCastException because inside New
var part = contentItem.Get<T>() makes part = null.
I think I may have fundamentally got what the ContentManager does quite mixed up, or there is something wrong with my model or data migration. Am I trying to do roughly the right thing, but have made a small mistake, or am I way off the mark?