【发布时间】:2015-07-25 17:32:19
【问题描述】:
我在访问要传递视图的模型的属性之一时遇到问题。
模型定义如下:
public class ProductBasket
{
public ProductBasket()
{
Products = new List<ProductConfiguration>();
Errors = new List<string>();
}
public List<ProductConfiguration> Products { get; set; }
public List<string> Errors { get; set; }
}
在我看来,模型指令是这样声明的:
@model MyApp.ViewModels.Product.ProductBasket
我无法在foreach 循环中访问Products 属性。在 VisualStudio 中,当我将 Model 变量悬停在循环中时,它会显示:
List<MyApp.ViewModels.Product.ProductConfiguration>
WebViewPage<List<MyApp.ViewModels.Product.ProductConfiguration>>.Model { get; }
这是我使用的以前的模型 - 我不知道为什么会出现这种情况?
我做了什么
本能告诉我,我应该能够使用 Model.Products 访问 Products 属性(如果这不正确,请告诉我),但我不明白为什么视图没有通过 ProductBasket 传递?
【问题讨论】:
-
检查您是否在控制器中传递了正确的模型,是的,您应该能够使用 Model.Products 访问产品。
标签: c# asp.net-mvc razor