我不斷收到錯誤,試圖遍歷視圖中的ViewData ...我甚至強烈嘗試向IEnumerable(App.Models.Namespace)鍵入視圖並使用Model,無濟於事。要麼因爲缺少GetEnumerable方法或無效類型轉換而出現錯誤...任何想法我如何做到這一點?爲什麼我無法通過ViewData或Model進行預覽?
型號...
public IQueryable<Product> getAllProducts()
{
return (from p in db.Products select p);
}
控制器...
public ActionResult Pricing()
{
IQueryable<Product> products = orderRepository.getAllProducts();
ViewData["products"] = products.ToList();
return 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>
嘗試已經,得到了一個無效的轉換錯誤 – BigOmega 2009-09-17 21:33:10
找出計算機[ 「產品」]真的是通過輸出 計算機[ 「產品」。的GetType( )。全名 – 2009-09-17 22:27:34