Html 如何解决System.Collections.Generic.List没有ProductID的定义或ProductID的方法?
以下是我的观点Html 如何解决System.Collections.Generic.List没有ProductID的定义或ProductID的方法?,html,css,asp.net-mvc,linq,Html,Css,Asp.net Mvc,Linq,以下是我的观点 @model List<EShopperTheme.Domain.Entities.Product> @using System.Linq @foreach (var item in Model) { <div class="col-sm-4"> <div class="product-image-wrapper"> <div class="single-products">
@model List<EShopperTheme.Domain.Entities.Product>
@using System.Linq
@foreach (var item in Model)
{
<div class="col-sm-4">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<!--Add to Cart Button Here-->
@using (Html.BeginForm("AddToCart", "Cart"))
{
@Html.HiddenFor(x => x.ProductID)
@Html.Hidden("returnUrl", Request.Url.PathAndQuery)
<input type="submit" class="btn btn-default add-to-cart" value="Add to cart" />
}
</div>
</div>
</div>
</div>
</div>
}
@型号列表
@使用System.Linq
@foreach(模型中的var项目)
{
@使用(Html.BeginForm(“AddToCart”、“Cart”))
{
@Html.HiddenFor(x=>x.ProductID)
@隐藏(“returnUrl”,Request.Url.PathAndQuery)
}
}
我在运行应用程序时遇到上述错误,我也添加了@using.linq,但它并没有解决问题,我仍然会遇到这个错误。我认为这应该可以解决问题(在使用项目之前,您必须放置@):
在foreach循环中用@item替换item的所有用法我认为这应该可以解决问题(在使用item之前必须先放@code):
在foreach循环中将item的所有用法替换为@item您需要将hidden更改为
@Html.HiddenFor(x=>item.ProductID)
按照您的方式,您正在尝试访问System.Collections.Generic.List(这是您的模型)中不存在的属性,但您需要访问当前为ProductID迭代的
项。您需要将隐藏更改为@Html.HiddenFor(x=>item.ProductID)
按照您的方式,您正在尝试访问System.Collections.Generic.List(您的模型)中不存在的属性,但是您需要访问当前的项,您正在迭代ProductID。我没有问题,我在add-to-Cart中有问题,您的产品类看起来怎么样?我没有问题,我在add-to-Cart中有问题,您的产品类看起来怎么样?您很有天赋,你是从哪里学到这些的?你真是个天才,你从哪里学到的?英雄联盟