Copied to clipboard

Flag this post as spam?

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


  • Sonja 133 posts 621 karma points
    Sep 25, 2018 @ 06:19
    Sonja
    0

    Loading the list in the model

    Hi, I need to display a list of items. How do I add this list to the mvc model?

    I have

    @Html.Partial("~/Views/Partials/TwoColumnRight.cshtml",
            new MyProject.Models.MyContentList()
            {
                Target = @Umbraco.Field("Target").ToHtmlString(),
                [email protected]("ContentType").ToString(),
                [email protected]("stackedContentListTitle").ToString(),
               Items=???    
    
            }
    

    and the model

    public class MyContentList
        {
            public string Text { get; set; }
    
            public List<MyContent> Items { get; set; }
    
            public string ItemType { get; set; }
    
    
            [DefaultValue("_blank")]
            public string Target { get; set; }
            public MyContentList()
            {
            }
    
    
        }
    

    Please advice how do I load the items in the first code block?

  • louisjrdev 107 posts 344 karma points c-trib
    Sep 25, 2018 @ 07:10
    louisjrdev
    0

    Hi,

    Would you not just need:

    [email protected]("alias").ToList()
    
  • Sonja 133 posts 621 karma points
    Sep 25, 2018 @ 11:24
    Sonja
    0
    System.Web.IHtmlString' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Web.IHtmlString' could be found (are you missing a using directive or an assembly reference?)
    

    so this doesn't work

  • louisjrdev 107 posts 344 karma points c-trib
    Sep 25, 2018 @ 11:33
    louisjrdev
    0

    What does the data look like that you are trying to store, it looks like you are trying to store content of an RTE into a list? I question whether there is a better approach for your fieldtype in the CMS for what you are trying to do.

    If you are sure you need to use that field type, try doing .ToString() before the .ToList() but this may not parse the data correctly as the RTE can have a variety of rich text content.

  • Sonja 133 posts 621 karma points
    Sep 25, 2018 @ 12:17
    Sonja
    0

    The problem is that the list is not even displayed in the Fields.

  • Sonja 133 posts 621 karma points
    Sep 25, 2018 @ 12:53
    Sonja
    0

    also @Umbraco.Field("something").ToList() does not exist

  • Sonja 133 posts 621 karma points
    Oct 03, 2018 @ 05:21
    Sonja
    0

    I did it with FOR loop manually transferring every item. if someone has better solution please tell

Please Sign in or register to post replies

Write your reply to:

Draft