是否可以在Asp.NET剃刀代码中嵌套foreach循环?

时间:2013-12-16 06:55:52

标签: c# asp.net asp.net-mvc razor

我有以下代码,我希望有一个内部foreach循环,但代码不会通过添加内部循环进行编译。任何帮助将不胜感激。

foreach (var answer in q.Answers)
{
    <input type="checkbox" name="AnswerDetails" value="@answer.AnswerText" data-answerid="@answer.Id">@answer.AnswerText<br />

    foreach (var research in @answer.ResearchSet)
    {
       @:<p>@research.Image</p>
    }
}

1 个答案:

答案 0 :(得分:6)

@foreach (var answer in q.Answers)
{
    <input type="checkbox" name="AnswerDetails" value="@answer.AnswerText" data-answerid="@answer.Id" />@answer.AnswerText<br />

    foreach (var research in answer.ResearchSet)
    {
       <p>@research.Image</p>
    }
}