你能幫我理解泛型集合有什麼問題嗎?提前致謝!ASP.Net MVC模型問題
錯誤:傳遞到字典中的模型項類型爲'System.Collections.Generic.List 1[DomainModel.Product]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [DomainModel.Entities.Product]'。
MODEL:
namespace DomainModel.Concrete
{
public class SqlProductsRepository : IProductsRepository
{
private Table<Product> productsTable;
public SqlProductsRepository(string connString)
{
productsTable = (new ProaductDataContext(connString)).GetTable<Product>();
}
public IQueryable<Product> Products
{
get { return productsTable; }
}
}
}
接口
namespace DomainModel.Abstract
{
public interface IProductsRepository
{
IQueryable<Product> Products { get; }
}
}
VIEW
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/ViewMaster.Master"
Inherits="System.Web.Mvc.ViewPage<IEnumerable<DomainModel.Entities.Product>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Products
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% foreach (var product in Model)
{ %>
<div class = "item">
<h3> <%=product.Name%></h3>
<%= product.Description%>
<h4><%= product.Price.ToString("c")%></h4>
</div>
<%} %>
</asp:Content>
你是我的英雄!謝謝,我一整個早上都在忙着這個。我正在通過一本教科書中的教程,看起來這本書是一個錯誤。 – Susan