AngularJs - 从关联的类和集合传递数据

时间:2013-03-07 16:01:29

标签: class collections angularjs

我的膳食类(服务器端)

公共课用餐 {

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>

问题:

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

1 个答案:

答案 0 :(得分: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>