我有一个网站,当您订购2个产品时,它们会被添加到数据库中,因此我知道我有这个模型
public IQueryable<CommonLayer.Models.OrdersModel> GetOrderAsModel(Guid id)
{
return (from p
in this.Entities.ORDERS
join orderdetails in this.Entities.ORDERDETAILS on p.OrderId equals orderdetails.OrderDetailsOrderId
where p.OrderId == id
select new CommonLayer.Models.OrdersModel()
{
Orderid = p.OrderId,
Orderdetailsid = orderdetails.OrderDetailsOrderId,
OrderDate = p.OrderDate,
Orderstatus = p.OrderStatus,
ProductQty = orderdetails.ProductQuantity,
OrderNum = p.OrderNum,
Userid = p.UserId,
ProductName = orderdetails.PRODUCT.ProductName
});
}
This model return the order along with the order details(if for example i have two products i have two orderdetails)
现在我正在尝试添加从订单中更改某些字段的值的功能,并且我正在尝试以特定顺序获取所有产品,如果我有例如它返回的4个产品但它们都完全像第一个产品进入即使我有不同的产品,即使数量如果在订单中我有一个产品1和另外5个它返回两个产品同名相同的数量。下面的代码显示了我想要实现的每一个:
@foreach (var item in Model)
{
<div class="form-group">
@Html.LabelFor(model => model.FirstOrDefault().ProductName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FirstOrDefault().ProductName, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FirstOrDefault().ProductQty, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FirstOrDefault().ProductQty, new { htmlAttributes = new { @class = "form-control" }})
</div>
</div>
}