0

我的膳食课堂(服务器端)

公共课餐{

public Meal()
{
    Fruits = new List<Fruit>();
}

public int Id { get; set; }
public string Name { get; set; }

[ForeignKey("Fk_VendorId")]
public virtual Vendor Vendor { get; set; }
public int Fk_VendorId { get; set; }

//collection
public virtual ICollection<Fruit> Fruits  { get; set; }

}

表单HTML:

 <div ng-controller="MealCtrl>
 <select ng-model="meal.Id" ng-options="meal.Id as meal.Name for meal in Meals"></select>
 </div>

 <div ng-controller="FruitCtrl>
 <select ng-model="???" ng-options="fruit.Id as fruit.Name for fruit in fruits"></select>
 </div>

 <div ng-controller="VendorCtrl>
 <select ng-model="???" ng-options="vendor.Id as vendor.Name for vendor in vendors"></select>
 </div>

问题:

如何在提交时将选定的关联类 [Vendor] 和关联的集合 [Fruits] 传递给 Meal 类?

4

1 回答 1

0

将关闭的 MealCtrl div 移动到末尾,并将 meal.FK_VendorId 添加为供应商的 ng-model。

<div ng-controller="MealCtrl>
 <select ng-model="meal.Id" ng-options="meal.Id as meal.Name for meal in Meals"></select>

<div ng-controller="FruitCtrl>
<select ng-model="???" ng-options="fruit.Id as fruit.Name for fruit in fruits"></select>
</div>

<div ng-controller="VendorCtrl>
<select ng-model="meal.Fk_VendorId" ng-options="vendor.Id as vendor.Name for vendor in vendors"></select>
</div>

</div>
于 2013-03-07T16:22:30.987 回答