【发布时间】:2017-12-24 06:58:46
【问题描述】:
我有一个预付产品销售。 经销商可以有子经销商 经销商可以为每个产品定价 他对每种产品都有最大的义务。 现在我喜欢在我的 mvc c# 站点项目中的销售页面中有两个 DropDowmList 当我从第一个 ddl 中获取产品时,我希望我的另一个 ddl(他必须销售多少产品)从我的数据库中连接。
编辑: 例如,经销商要销售三种产品: productA - 5 件待售 产品B - 20 产品C - 15 当他在第二个 ddl 或 textboxForNumber(min,max) 上选择 productB 时,他应该看到从 1 到 20 的范围
我尝试像这样创建一个新模型:
public int ProductObligoByDealerID { get; set; }
public int DealerID { get; set; }
public virtual Dealer Dealer { get; set; }
public int ProductID { get; set; }
public virtual Product Product { get; set; }
public uint MonthObligo { get; set; }
但我无法将这两个 ddl 连接在一起。
编辑:
我尝试使用 ViewBag 来执行此操作,就像其他 ddl 资源列表一样。
var AllObligoProdact = db.ProductObligo.Where(p => p.DealerID == currentDealer.DealerID);
foreach (var item in AllObligoProdact)
ViewBag.ProductObligo[item.Product.ProductID].max = item.MonthObligo;
在cshtml端
<div class="editor-label">
@Html.LabelFor(model => model.DealerProductID)
</div>
<div class="editor-field">
@Html.DropDownList("DealerProductID", string.Empty)
@Html.ValidationMessageFor(model => model.DealerProductID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.NumOfMonth)
</div>
<div class="editor-field">
@*Html.EditorFor(model => model.NumOfMonth)*@
@Html.TextBoxFor(model => model.NumOfMonth , new {type="number",min="0",max=ViewBag.ProductObligo[Model.DealerProductID].max })
@*.DropDownList("NumOfMonth", string.Empty)*@
@Html.ValidationMessageFor(model => model.NumOfMonth)
</div>
但我仍然一无所获:/ 在数据库中使用新表是个好主意,或者有更好的方法来做到这一点?
【问题讨论】:
标签: c# asp.net-mvc-4