View: Compilation error (line 24, col -1): Using the generic type 'System.Collections.Generic.IEnumerator<T>' requires 1 type arguments RRS feed

  • Question

  • User87195929 posted

    Hi all

    I am ref the link https://dotnetfiddle.net/Xds08j

    I have changed, the code  in view like

    @model IEnumerable<DemoApp.Person>
    Layout = null;

    <head><title> Demo</title></head>

    <h1> People</h1>

    @IEnumerator EmpEnumerator = Model.GetEnumerator();

    @while (EmpEnumerator.MoveNext())



    but i am geting error like

    View: Compilation error (line 24, col -1): Using the generic type 'System.Collections.Generic.IEnumerator<T>' requires 1 type arguments

    so  do not use alternate code , for this

    use this only to display the 


    • Bob
    • John
    Monday, February 3, 2020 10:31 AM

All replies

  • User753101303 posted


    As you are using IEnumerable<DemoApp.Person>, GetEnumerator returns IEnumerator<DemoApp.Person>. IEnumerable would return IEnumerable.

    Not sure what is the point of coding explicitly what foreach does for you behind the scene?

    Monday, February 3, 2020 10:53 AM
  • User-1780421697 posted

    I you simply want to display the people list here, 

    First make sure that in your controller  -> action  method returns  IEnumerable<DemoApp.Person> to View and its right type that is expected as model in view.

    Second you can print this in for each by getting the Model and  

    //Assume that person class have a property "Name"
    @foreach (var p in Model)

    Tuesday, February 4, 2020 4:50 AM
  • User665608656 posted

    Hi siddangoud,

    According to your modified content, these cannot be presented in the view page.

    The tutorial you provided in the link is the simplest and most common way of writing.

    Why would you use custom variables for display?

    The reference link is the best way, you don't need to complicate the content.

    Best Regards,


    Tuesday, February 4, 2020 5:41 AM