Replicated nested repeater behaviour in MVC
Today I decided to give MVC a go, and although I really like the idea, I found it fairly difficult to transition from ASP.NET and grasp some basic concepts, like using foreach instead of nested repeaters.

It took me good few hours to come up with this solution, but it doesn't seem quite right. Could someone please explain what's wrong with this code, and what the right way to do it is. Here is my solution:

Essentially it's a survey that consists of several questions, each of which has several answers. I have tables in db, which are represented as strongly typed entities. The controller looks like this:

    public ActionResult Details(int id)
    {
        return View(new Models.Entities().Questions.Where(r => r.PROMId == id));
    }

and corresponding view like this:

    <% foreach (var question in Model) { %>
        
        <h3>Question <%: Array.IndexOf(Model.ToArray(), question) + 1 %></h3>
        <p><%: question.QuestionPart1 %></p>
        <p><%: question.QuestionPart2 %></p>
        <% var answers = new Surveys_MVC.Models.Entities().Answers.Where(r => r.QuestionId == question.QuestionId); %>
        <% foreach (var answer in answers) { %>
            <input type="radio" /><%: answer.Text %>
        <% } %>
        
    <% } %>

All feedback appreciated.
Replicated nested repeater behaviour in MVC
===

Today I decided to give MVC a go, and although I really like the idea, I found it fairly difficult to transition from ASP.NET and grasp some basic concepts, like using foreach instead of nested repeaters.

It took me good few hours to come up with this solution, but it doesn't seem quite right. Could someone please explain what's wrong with this code, and what the right way to do it is. Here is my solution:

Essentially it's a survey that consists of several questions, each of which has several answers. I have tables in db, which are represented as strongly typed entities. The controller looks like this:

    public ActionResult Details(int id)
    {
        return View(new Models.Entities().Questions.Where(r => r.PROMId == id));
    }

and corresponding view like this:

    <% foreach (var question in Model) { %>
        
        <h3>Question <%: Array.IndexOf(Model.ToArray(), question) + 1 %></h3>
        <p><%: question.QuestionPart1 %></p>
        <p><%: question.QuestionPart2 %></p>
        <% var answers = new Surveys_MVC.Models.Entities().Answers.Where(r => r.QuestionId == question.QuestionId); %>
        <% foreach (var answer in answers) { %>
            <input type="radio" /><%: answer.Text %>
        <% } %>
        
    <% } %>

All feedback appreciated.