所以我从头开始道歉,我是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调用中看不到任何内容。
我已尝试通过帖子和直接路径直接调用服务器,但也没有用。
答案 0 :(得分:1)
你应该添加属性:
mod.controller('BrandingController', ['$scope', '$http', function(brandModel, $http) {
并调用:
brandModel.update = function() {
$http.post("@Url.Action("SaveBranding","AirlineConfig")", brandModel.model);
//.success and .fail never are triggered when implemented
};
您的brandModel.model是BrandingViewModel。