I have an HTML form in a blocklist item. When that form is submitted, I want the receiving generic MVC controller to look up some Model.Settings from that same block list item.
If I include a hidden field in my form that contains the "Key" guid of the Model.Settings, then in my destination controller I thought I would be able to look up that same block list item's settings but when I try
If, however, I pass the key of my parent document (Umbraco.AssignedContentItem.Key,) then I am able to at least retrieve the document, after which I am looping through the document properties trying to find my block list then my block list item but it is feeling weird and the code is ugly and contains some fragile bits.
Any idea if I'm on the right track or why block list items don't seem to be found by GetById()?
This is what the final code looks like. It requires that I not only send the block list element's key as a hidden field, but also the key of the containing parent document as a second hidden field. Let me know if you can think of a simpler way to do this.
var parentPage = umbracoHelper.Content(parentPageKey);
foreach (var property in parentPage!.Properties)
{
if (property.PropertyType.DataType.EditorAlias == "Umbraco.BlockList")
{
foreach (var item in property.Value<BlockListModel>(null!)!)
{
if (item.Content is FormElement && item.Settings is FormSettingsElement)
{
FormSettingsElement formSettingsElement = (FormSettingsElement)item.Settings;
if (formSettingsElement.Key == formSettingsKey) // If there are two forms in the blocklist, making sure this is the one that was submitted
{
string toAddress = formSettingsElement.RecipientEmailAddress!;
string formName = formSettingsElement.FormName!;
}
}
}
}
}
Find block list item by Key
I have an HTML form in a blocklist item. When that form is submitted, I want the receiving generic MVC controller to look up some Model.Settings from that same block list item.
If I include a hidden field in my form that contains the "Key" guid of the Model.Settings, then in my destination controller I thought I would be able to look up that same block list item's settings but when I try
I get [null].
If, however, I pass the key of my parent document (Umbraco.AssignedContentItem.Key,) then I am able to at least retrieve the document, after which I am looping through the document properties trying to find my block list then my block list item but it is feeling weird and the code is ugly and contains some fragile bits.
Any idea if I'm on the right track or why block list items don't seem to be found by GetById()?
I experience the same behavior using an UmbracoHelper BTW
This is what the final code looks like. It requires that I not only send the block list element's key as a hidden field, but also the key of the containing parent document as a second hidden field. Let me know if you can think of a simpler way to do this.
is working on a reply...