//产品
public class Product
{
[Key]
public int ID {get; set;}
public string PK {get; set;}
[Required(ErrorMessage="Category is required field.")]
public int CategoryID { get; set; }
[Required]
public string Title {get; set;}
public virtual ICollection<Pricing> Pricing { get; set; }
}
// 价钱
public class Pricing
{
[Key]
public int ID {get; set;}
public int ProductID {get; set;}
public decimal Price {get; set;}
public int OrderQty {get; set;}
public string PK { get; set; }
}
我喜欢上面的实体表,我想在更新产品页面中为 ICollection 绘制 5 个文本框。但我不知道,我该怎么做。
@model BrownieDAL.Entities.Product
<th> Price / Order Qty</th>
<td>
@{int priceCnt = 0;}
@foreach(var price in Model.Pricing){
priceCnt++;
@Html.TextBoxFor(model => price.Price)
@Html.TextBoxFor(model => price.OrderQty)
<br />
}
@if (priceCnt < 5)
{
// ???
@Html.TextBoxFor(Model.Pricing => Model.Pricing.Price)
priceCnt++;
}
</td>
当我尝试使用“@Html.TextBoxFor(Model.Pricing => Model.Pricing.Price)”时,我收到一条错误消息:
Error 1 'System.Collections.Generic.ICollection<PJ.Entities.Pricing>' does not contain a definition for 'Price' and no extension method 'Price' accepting a first argument of type 'System.Collections.Generic.ICollection<PJ.Entities.Pricing>' could be found (are you missing a using directive or an assembly reference?)
有人知道,我应该如何为 ICollection<> 属性绘制文本框?