I am very new to MVC and am looking for the best way to handle access to the Enumerator of the following class when used as the type of a View:
public class TemplateCollection : IEnumerable<Template>
{
private IEnumerable<Template> templates;
public TemplateCollection()
{
LoadTemplates();
}
public IEnumerator<Template> GetEnumerator()
{
return templates.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return templates.GetEnumerator();
}
}
My view (more or less):
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TemplateCollection>" %>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<%foreach(var template in ViewData ??) %>
</asp:Content>
How do I access the Enumerator in my foreach loop? Or do I need to create a container class that exposes my TemplateCollection as a property and access that view ViewDate["TemplateCollection"] ?
Thanks,