【发布时间】:2016-02-21 23:00:05
【问题描述】:
我不知道发生了什么,但这个功能似乎根本不起作用。
这是我的看法:
<tr>
<th>Category</th>
<td>
<select class="form-control" ng-model="masterlist.category_id" ng-options="c.category_id as c.category_name for c in category" required data-ng-change="getSubCategory(c.category_id)"></select>
</td>
</tr>
<tr>
<th>Sub Category</th>
<td>
<select class="form-control" ng-model="masterlist.sub_category_id" ng-options="c.sub_category_id as c.sub_category_name for c in subCategory" required></select>
</td>
</tr>
角度 JS
$scope.getSubCategory = function (category_id) {
$http.get('/MasterList/SubCategory' + category_id).then(function ($response) {
$scope.subCategory = $response.data;
});
}
控制器:
public ActionResult SubCategory(int id)
{
db.Configuration.ProxyCreationEnabled = false;
return Json(db.Sub_Category.Where(x => x.active_flag == true && x.category_id == id).ToList(), JsonRequestBehavior.AllowGet);
}
我在控制台上检查但没有任何错误,这是检查元素视图:
我的主要目标是一旦选择了类别,子类别的显示将只显示该类别下的那些。
提前感谢您的帮助。
【问题讨论】:
-
是否在进行 ajax 调用?
-
Url 将是无效的连接字符串的方式。你不是想念
/吗?在浏览器开发工具网络中检查 ajax 请求非常容易。还应该添加一些错误处理 -
当您更改下拉列表中的某些内容时,它是否正在执行您的 getSubCategory 方法中的代码(http get)?检查浏览器网络标签
-
我放了 / 但还是不行。它不是去 getCategory 控制器,
标签: angularjs asp.net-mvc-4 angularjs-ng-change