tags:

views:

374

answers:

2

I am trying to follow this example: Creating Model Classes with the Entity Framework (C#) .
I am getting an error when I try to this:

ViewData.Model = _db.MovieSet.ToList();

In my intellisense, I do not get the ToList()

Here is the code:

using System.Linq;
using System.Web.Mvc;
using MovieEntityApp.Models;

namespace MovieEntityApp.Controllers
{
[HandleError]
public class HomeController : Controller
{
    MoviesDBEntities _db;

    public HomeController()
    {
        _db = new MoviesDBEntities();
    }


    public ActionResult Index()
    {
        ViewData.Model = _db.MovieSet.ToList();
        return View();
    }

}
}

I am trying to display the results in the a Repeater on the View, can anyone help with what the code would look like in the code behind as well as the ASPX page.

+5  A: 

The Repeater is designed for web form and works with the web forms events. In MVC you really want to avoid data bound controls like Repeater, GridView, ListView. It's pretty easy to spit the movies out in a loop, however:

<% foreach (var item in Model) { %>

        <tr>
            <td>
                <%= Html.Encode(item.Title) %>
            </td>
            <td>
                <%= Html.Encode(item.ReleaseDate.Year) %>
            </td>
            ...
        </tr>

<% } %>
OdeToCode
+1  A: 

create a HTML Helper for your repeater - refer here

Rony
Very nice ... I'm going to use that.
Richard Hein