Displaying multinode picker within list of members
Hi Folks,
I've got a multinode picker as a custom data type within a member - I can't pull back the data to the front end as a list.
@foreach (var member in ApplicationContext.Current.Services.MemberService.GetAllMembers().OrderBy(member => member.Name))
{
<tr>
<td>@member.Name </td>
<td>@member.Email</td>
<td>@member.GetValue("TownCity")</td>
<td>@member.GetPropertyValue<IPublishedContent>("Pharmacy")</td>
</tr>
}
I would think the last row should work but it's throwing an error - Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
Not tried this before, so I'm a bit stuck. Any ideas will be greatly appreciated.
Dead topic, but this is the closest i could find to my problem.
var listOfTradesmen = listOfMembers.Where(tradesman => tradesman.ContentType.Alias.Equals("tradesmanMember") && tradesman.GetValue<IEnumerable<IPublishedContent>>("services").Select(service => service.Id).Intersect(categoryServicesAsListOfIds).Any());
I have an MNTP as a field for Members, and by looking at the ModelsBuilder generated code of my member type, I did exactly the same code you suggested Darren, but alas I get a 'Value cannot be null' exception.
The field names match, and if I remove the IEnumerable return type so that I let the method decide what to return back, it returns back a stringified list of UDIs, which only complicates fitlering and searching of members now.
By any chance, do you know if I can simplify or make minimal changes to my code so that I do not need to mess around with UDIs, convert to GUID, look them up, etc etc. ? The process seems unnecessarily complicated now.
I had made a helper class containing 2 methods, one to look up the UDI as a typed content and the other to read a list of them.
public static IPublishedContent GetPublishedContentByUdi(string udi)
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
return udi.IfNotNull(x => umbracoHelper.TypedContent(x)) ?? default(IPublishedContent);
}
/// <summary>
/// Takes a stringified list of UDIs to return as IEnumerable of type IPublishedContent
/// </summary>
/// <param name="udi"></param>
/// <returns></returns>
public static IEnumerable<IPublishedContent> GetPublishedContentByListOfUdis(object udi)
{
return udi
.IfNotNull(x => x
.ToString()
.Split(',')
.Select(GetPublishedContentByUdi)) ?? Enumerable.Empty<IPublishedContent>();
}
In the end, my code for my scenario from my previous post came to look like so (the name of my helper is PublishedContentHelper):
Displaying multinode picker within list of members
Hi Folks,
I've got a multinode picker as a custom data type within a member - I can't pull back the data to the front end as a list.
I would think the last row should work but it's throwing an error - Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
Not tried this before, so I'm a bit stuck. Any ideas will be greatly appreciated.
Cheers Darren
Hi Darren,
When you say the last line, do you mean:
If so, is there a Property on the MemberDocType named "Pharmacy" and is it a node?
Thanks
Craig
Hi Craig,
Thanks for getting back to me - that's the correct line. There's a multi node picker on the MemberDocType called Pharmacy.
Cheers Darren
Hi Darren,
You should be able to do something like below:
This should return a list of selected IPublishedContent objects.
Thanks
Craig
Dead topic, but this is the closest i could find to my problem.
I have an MNTP as a field for Members, and by looking at the ModelsBuilder generated code of my member type, I did exactly the same code you suggested Darren, but alas I get a 'Value cannot be null' exception.
The field names match, and if I remove the IEnumerable return type so that I let the method decide what to return back, it returns back a stringified list of UDIs, which only complicates fitlering and searching of members now.
By any chance, do you know if I can simplify or make minimal changes to my code so that I do not need to mess around with UDIs, convert to GUID, look them up, etc etc. ? The process seems unnecessarily complicated now.
Hi Julian, did you found solution for this?
Hi Silvija,
My solution was to go along with the UDIs.
I had made a helper class containing 2 methods, one to look up the UDI as a typed content and the other to read a list of them.
In the end, my code for my scenario from my previous post came to look like so (the name of my helper is PublishedContentHelper):
is working on a reply...