Copied to clipboard

Flag this post as spam?

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


  • Uriel Antonio Sánchez 6 posts 87 karma points
    Jan 29, 2019 @ 18:53
    Uriel Antonio Sánchez
    0

    Help with umbraco headless and .net

    Hello everyone, I'm starting with the test example of 'Asp.net Framework website' and already configure the class and the controller.

    But I have problems with the view, it marks me an error in the IEnumerable code line. Could someone guide me? (Attachment screenshot).

    I am using Visual Studio 2017 and framework 4.6.1

    enter image description here

  • Rhys Hamilton 140 posts 942 karma points
    Jan 30, 2019 @ 23:50
    Rhys Hamilton
    1

    To resolve your issue, you need to specify the type of your IEnumerable, as well as including your @using statement at the top of your file, like so:

    @using Umbraco.Headless.Client.Net.Models
    @model IEnumerable<ContentItem>
    
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 31, 2019 @ 09:10
    Jan Skovgaard
    1

    Hi Uriel

    I have not been playing aorund with Headles and .NET myself but I just want to make sure you're aware that there is some documentation available here too? https://our.umbraco.com/documentation/Umbraco-Cloud/Headless/Headless-Net-Client/ :-)

    /Jan

  • Uriel Antonio Sánchez 6 posts 87 karma points
    Jan 31, 2019 @ 15:25
    Uriel Antonio Sánchez
    0

    Hi Jan,

    Thank you for your response, I'm just taking the example of the documentation that you share with me.

    However I managed to solve the problem by removing the IEnumerable and it worked so far, I still have confusion about using and how to use the IEnumerable but I think I can continue for the moment.

    Thanks for your time.

  • Uriel Antonio Sánchez 6 posts 87 karma points
    Jan 31, 2019 @ 15:26
    Uriel Antonio Sánchez
    0

    Hi Rhys,

    I already applied the solution you gave me, but the error still appears in the foreach, however, I have eliminated the IEnumerable and it works well for me. Do you know why this happens?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 31, 2019 @ 20:12
    Jan Skovgaard
    0

    Hi Uriel

    Ah ok - Just wanted to make sure. But it occurs to me that some of the examples might not have been correct? Do you mind referencing the part of the documentation where you got stuck? Because then it's possible to have it updated with the correct way of going about it so others don't face the same issues that you have experienced :-)

    /Jan

  • Uriel Antonio Sánchez 6 posts 87 karma points
    Jan 31, 2019 @ 21:41
    Uriel Antonio Sánchez
    0

    Of course,

    Headless .NET client> ASP.NET Framework website> Create a view at /Views/Home/Headless.cshtml

    I add the url too: https://our.umbraco.com/documentation/Umbraco-Cloud/Headless/Headless-Net-Client/website-framework

    Thanks for your time.

  • Harry Spyrou 212 posts 604 karma points
    Jan 31, 2019 @ 15:45
    Harry Spyrou
    102

    Hey Uriel,

    IEnumerable is an interface that exposes the Enumerator. Your model is something different. Your model is basically a data dump of variables that you can use in views when they get populated

    What a model looks like:

    Taken from here

    namespace MVC_BasicTutorials.Models
    {
        public class Student
        {
            public int StudentId { get; set; }
            public string StudentName { get; set;  }
            public int Age { get; set;  }
        }
    }
    

    Then in a view you can do this:

    @model Student
    
    <h1>@Model.StudentId</h1>
    

    You can find IEnumerable here To put it as simply as I can, IEnumerable allows you to loop through stuff like collections.

  • Uriel Antonio Sánchez 6 posts 87 karma points
    Jan 31, 2019 @ 16:06
    Uriel Antonio Sánchez
    1

    Harry,

    Thank you very much, you have helped me a lot, This solves my problem.

  • Harry Spyrou 212 posts 604 karma points
    Jan 31, 2019 @ 16:18
    Harry Spyrou
    0

    Glad I could help

Please Sign in or register to post replies

Write your reply to:

Draft