我正在使用ASP.NET MVC 5,并使用html.checkboxfor。
进行复选框。<div class="col-md-6">
@Html.CheckBoxFor(m => m.active, new {
@class = "form-control populate", @id = 'EditActive',
@ng_model = "editFormData.active"
})
</div>
当我在ajax调用后设置angularjs editformdata时,当我以{{editformdata}}将其输出到屏幕上时,该值是正确的,但是复选框未显示为已检查。
datatableApp.controller('EditFormController', ['$scope', '$http', function($scope, $http) {
$scope.getEditStreet = function(streetID) {
$http.post('@Url.Action(Model.GetFormControllerFunctionName, Model.GetFormControllerName)', "{ @Model.JavascriptEditPropertyName : " + streetID + "}").then(function(response) {
alert("success");
$scope.editFormData = response.data.ResultObject;
},
function(response) {
alert("fail" + response.statusText);
});
};
}]);
ResultObject包含一个活动字段,该字段正确地显示为真或错误。
如何获得复选框的剃须刀版本?
我弄清楚了。显然,当您修改某些值时,您需要具有$ scope.apply()。不确定所有这些情况是什么,但我添加了它,现在正常工作。
datatableApp.controller('EditFormController', ['$scope', '$http', function($scope, $http) {
$scope.getEditStreet = function(streetID) {
$http.post('@Url.Action(Model.GetFormControllerFunctionName, Model.GetFormControllerName)', "{ @Model.JavascriptEditPropertyName : " + streetID + "}").then(function(response) {
alert("success");
$scope.editFormData = response.data.ResultObject;
$scope.$apply();
},
function(response) {
alert("fail" + response.statusText);
});
};
}]);