简体   繁体   中英

IEnumerable<ViewModel>' does not contain a definition for list

I have this viewmodel :

public class ViewModel
{
    public int Id { get; set; }

    public List<Class1> OutputList { get; set; }
}

I passing it to partial view in controller :

foreach (Class1 sc in linqQuery)
        {
            var viewModel = new ViewModel
            {
                Id = sc.Id,
                OutputList = sc.CodeExecutionResults.Where(s => s.Id == sc.Id).ToList()
            };

            model.Add(viewModel);
        }

return this.PartialView(model);

And then, in view cshtml i want to display that OutputList :

@model IEnumerable<Models.ViewModel>

@foreach (var item in Model)
{
    <tr>
        <td style="width:30%">
           @foreach (var result in Model.OutputList)
           {
                <li> result.item </li>
           }
        </td>
    </tr>
}

But i get this output:

Error CS1061 'IEnumerable' does not contain a definition for 'OutputList' and no accessible extension method 'OutputList' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?)

My question is, how to get nested list in IEnumerable<ViewModel> in cshtml ?

use item.OutputList

@model IEnumerable<Models.ViewModel>

    @foreach (var item in Model)
    {
        <tr>
            <td style="width:30%">
               @foreach (var result in item.OutputList)
               {
                    <li> result.item </li>
               }
            </td>
        </tr>
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM