I'm building a website in ASP.Net, using MVC, and need to list a set of results. Both of the following work as I want them to but I'm wondering which is faster, cleaner and/or better - or if another option entirely would be more appropriate?
Note: ViewData.Model
is of type IEnumerable<Thing>
and I need to display more attributes than Name
- I've cropped the code for this example.
<% foreach (var thing in ViewData.Model)
{ %>
<p><%= thing.Name %></p>
<% }; %>
<% rptThings.DataSource = ViewData.Model;
rptThings.DataBind(); %>
<asp:Repeater ID="rptThings" runat="server">
<ItemTemplate>
<p><%# DataBinder.Eval(Container.DataItem, "Name") %></p>
</ItemTemplate>
</asp:Repeater>