Reputation: 5238
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
?
Upvotes: 0
Views: 1431
Reputation: 4298
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>
}
Upvotes: 3