【发布时间】:2015-02-10 19:53:39
【问题描述】:
我想使用 angularjs 将下拉选择的 countryId 绑定到我的班级 CountryId 和 Selected Stateid Value 到 StateId。
我的国家和州下拉菜单已成功加载。
这是我的模特:
public partial class Friends
{
public int Id { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string address { get; set; }
public string postalcode { get; set; }
public string notes { get; set; }
public Nullable<int> CountryId { get; set; }
public Nullable<int> StateId { get; set; }
}
这是我的观点:
<select data-ng-model="newfriend.country2" data-ng-options="c as c.Name for c in allItems" data-ng-change="">
<option value="">-- Select Country --</option>
</select>
<label>State:</label>
<select data-ng-model="newfriend.state2" data-ng-disabled="!newfriend.country2" data-ng-options="s.Id as s.Name for s in newfriend.country2.State">
<option value="">-- Select State --</option>
</select>
这是我通过一种方法获取两个国家/地区状态的控制器方法:
public JsonResult GetCountryState()
{
var Data = db.Country.Select
(
d => new CountryModel
{
Id = d.Id,
Name = d.Name,
State = d.State.Select
(
x => new StateModel
{
Id = x.Id,
Name = x.Name
}
).ToList()
}
).ToList();
return Json(Data, JsonRequestBehavior.AllowGet);
}
这是我对添加控制器方法的调用:
$http.post('../Home/AddFriends', this.newfriend).success(function (data) {}
我想将我的值绑定到 FriendsModel 的控制器方法):
public ActionResult AddFriends(Friends FriendsModel)
{
}
谁能帮帮我???
【问题讨论】:
标签: asp.net-mvc angularjs select angularjs-scope