【发布时间】:2015-04-25 11:23:24
【问题描述】:
所以我从一开始就道歉,我对 AngularJS 很陌生。
所以我要做的就是将我视图中的模型传回给我的控制器。我尝试在互联网上进行搜索,但没有成功。
这是我现在拥有的:
(function() {
var mod = angular.module('branding', []);
mod.controller('BrandingController', ['$scope', '$http', function(brandModel) {
brandModel.model = dataModel.Views;
brandModel.SelectedName = "a";
brandModel.SelectedDescription = "s";
brandModel.SelectedIsBuiltIn = true;
brandModel.selectItem = function(view) {
brandModel.SelectedName = view.Name;
brandModel.SelectedDescription = view.Description;
brandModel.SelectedIsBuiltIn = view.IsBuiltIn;
};
brandModel.clearText = function() {
brandModel.SelectedName = "";
brandModel.SelectedDescription = "";
brandModel.SelectedIsBuiltIn = "";
};
brandModel.update = function($http) {
brandModel.apply(function() {
$http.post("@Url.Action("SaveBranding","AirlineConfig")");
//.success and .fail never are triggered when implemented
});
};
}]);
})();
我的控制器
[HttpPost]
public ActionResult SaveBranding(BrandingViewModel viewModel)
{
return View("Branding", viewModel);
}
我能够触发更新调用没有问题,但我从 http.post 调用中什么也没看到。
我已经尝试通过帖子和直接路径直接调用服务器,但这也不起作用。
【问题讨论】:
-
/AirlineConfig/SaveBranding的调试控制台中的网络请求/响应是什么样的? -
实际上网络选项卡什么也没显示,但控制台确实显示:无法获取未定义或空引用的属性“帖子”
-
你在控制器函数中缺少 $http...你只是在依赖列表中有它。
-
我认为您还需要从更新函数中删除 $http:brandModel.update = function() {
-
您在更新函数中重新定义 $http 的位置也进行了第二次更改?
标签: asp.net .net asp.net-mvc angularjs