我正在对Angular项目进行一些维护, 当将对象从控制器传递到服务时,我有一个奇怪的行为……为简单起见,我将读取的有效负载减少为一个字段
这里是Angular控制器
$scope.createNorm = function () {
var norma = {};
norma.IdType = -1;
createDialog({
title: "Creazione di una nuova norma",
template: NormeService.dialogTemplate,
okLabel: "Salva",
controller: ["$scope", "NormeService", function ($scope, NormeService) {
$scope.aziende = [];
$scope.tipoNorme = [];
var init = function () {
NormeService.getCompanyList().then(function (response) {
var arr = response.data.Items || [];
var aziende = [];
for (var i = 0; i < arr.length; i++) {
aziende.push({
Text: arr[i].Value,
Value: arr[i].Id
});
}
$scope.aziende = aziende;
});
NormeService.getNormTypesList().then(function (response) {
var arr = response.data || [];
var tipoNorme = [];
for (var i = 0; i < arr.length; i++) {
tipoNorme.push({
Text: arr[i].NAME,
Value: arr[i].ID
});
}
console.log(tipoNorme);
$scope.tipoNorme = tipoNorme;
});
};
init();
$scope.norma = angular.copy(norma);
$scope.value = $scope.norma;
}]
}).then(function (result) {
$scope.save(result);
}, function () { });
};
Angular服务
save: function (data) {
$http.post(baseUrl + "/save-norm2", { Norm:data});
},
服务数据模板
dialogTemplate: [
'<advancedselect options="tipoNorme" label="Tipo norma" ng-model="norma.IdType" type="text" ng-required="false" form-model="frm" />', /*ng - required="true"*/
MVC视图模型
public class TempViewModel
{
public int IdType { get; set; }
}
和MVC控制器
[System.Web.Http.HttpPost]
[System.Web.Http.Route("save-norm2")]
public IHttpActionResult SaveNorm(TempViewModel Norm)
{
return Ok(true);
}
正如您从屏幕快照中看到的那样,我已经在浏览器部分填充了校正后的值。
当它到达MVC上的Controller时,其IdType为0
我在做什么错了?