Last post Feb 04, 2020 05:41 AM by Yongqing Yu
Feb 03, 2020 10:31 AM|siddangoud|LINK
I am ref the link https://dotnetfiddle.net/Xds08j
I have changed, the code in view like
Layout = null;
@IEnumerator EmpEnumerator = Model.GetEnumerator();
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
Feb 03, 2020 10:53 AM|PatriceSc|LINK
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?
Feb 04, 2020 04:50 AM|Khuram.Shahzad|LINK
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)
Feb 04, 2020 05:41 AM|Yongqing Yu|LINK
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.