0

I have created a blocklist in Umbraco. I need that list data in my blazor page so I created an api method to fetch that data. I am getting data but not able to map/bind in my own model. That list also has an image element.

 public async Task<EmployeeDetailsLayout.EmployeeDetails> GetCompanyEmployeesLayoutpage(GenericContentPage genericContentPage)
        {
            try
            {

                EmployeeDetailsLayout.EmployeeDetails listEmployeeLayout = new EmployeeDetailsLayout.EmployeeDetails();

                if (_umbracoHelperAccessor.TryGetUmbracoHelper(out var umbracoHelper) is false)
                {
                    throw new Exception("Unable to get Umbraco Helper");
                }
                var _node1 = umbracoHelper.Content(1257);
                // var contentPage = GetGenericContentPage("companyemployees");
                if (_node1 is not null)
                {
                    var result = _node1.Value<dynamic>("Employees");
                    //   genericContentPage.BlockList.Select(x => x.GetCorrespondingElementModel()).ToList();
                    foreach (var item in result)
                    {
                        listEmployeeLayout.blockItems.Add(new EmployeeDetailsLayout.BlockItems { EmployeeName = item.Content.EmployeeName, EmployeeEmail = item.Content.EmployeeEmail, EmployeePosition = item.Content.EmployeePosition, EmployeePhone = item.Content.EmployeePhone, EmployeeImage= item.Content }) ;
                    }
                }
                // listEmployeeLayout = _mapper.Map<EmployeeDetailsLayout.EmployeeDetails>(listEmployeeLayout);
                return listEmployeeLayout;
            }
            catch (Exception ex)
            {

                throw ex;
            }


        }
  • Don't use dynamics. Retrieve your BlockList value as a strongly typed model. Your BlockList property will return an `IEnumerable`. That will make things easier to debug. – Mario Lopez Jan 16 '23 at 03:47

0 Answers0