I keep getting errors trying to iterate through my ViewData in the view there... I even tried strongly typing the view to IEnumerable(App.Models.Namespace) and using Model, to no avail. Either I get an error for lack of a GetEnumerable method or invalid type casting... Any idea how I do this?
Model...
public IQueryable<Product> getAllProducts()
{
return (from p in db.Products select p);
}
Controller...
public ActionResult Pricing()
{
IQueryable<Product> products = orderRepository.getAllProducts();
ViewData["products"] = products.ToList();
return View();
}
View...
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Pricing
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Pricing</h2>
<div>
<select class="product">
<%foreach(var prod in ViewData["products"]){%>
<option><%=prod.Title %></option>
<%} %>
</select><select></select>
</div>
</asp:Content>