Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Natalie 22 posts 162 karma points
    Jul 05, 2019 @ 13:41
    Natalie
    0

    impossible to convert lambda into string because not delegate

    Hello,

    I'm currently working on the 7.6.5 version of Umbraco and I wanna make a list of Question/Answer set.

    I've got tha lambda expression, trying lead to "sectionGeneric" DocumentTypeAlias... But I've got this error : "impossible to convert lambda into string because not delegate"

     public ActionResult RenderFaqList()
        {
            try
            {
                List<FaqModel> model = new List<FaqModel>();
                IPublishedContent section = CurrentPage.AncestorOrSelf(1).DescendantsOrSelf().Where(x => x.DocumentTypeAlias == "sectionGeneric").FirstOrDefault();
    
                foreach (IPublishedContent page in section.Children)
                {
                    model.Add(new FaqModel(page.GetPropertyValue<string>("question"), page.GetPropertyValue<string>("answer")));
                }
            }
    
            catch (NullReferenceException ex)
            {
                Console.WriteLine("Erreur de référence nulle : " + ex);
            }
    
            return PartialView(PARTIAL_VIEW_FOLDER + "_FAQ.cshtml");
        }
    

    Any clues ?!?

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Jul 08, 2019 @ 15:01
    Alex Skrypnyk
    1

    Hi Natalie

    Can you show "FaqModel" constructor? Maybe the issue is there, the code you showed looks fine.

    Thanks,

    Alex

  • Natalie 22 posts 162 karma points
    Jul 16, 2019 @ 07:10
    Natalie
    0

    Hello Alex !

    Sorry for that late replie, I was passing exams. So here is my FaqModel :

    namespace AsteraProjetLMS.Models
    {
        public class FaqModel
        {
            public string Question { get; set; }
            public string Answer { get; set; }
    
        public FaqModel(string question, string answer)
         {
            Question = question;
            Answer = answer;
        }
        } 
    }
    

    Thank you...

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Jul 16, 2019 @ 07:37
    Alex Skrypnyk
    100

    Natalie, please, check that you have a reference to "using System.Linq;" namespace.

  • Natalie 22 posts 162 karma points
    Jul 16, 2019 @ 12:40
    Natalie
    0

    Yes I do have it..... But it is noticed that the reference is not necessary...

  • Natalie 22 posts 162 karma points
    Jul 16, 2019 @ 12:44
    Natalie
    0

    Actually I add it int the controller and I don't have the error anymore...

    Thanks a million Alex !!! :)

Please Sign in or register to post replies

Write your reply to:

Draft