时间:2021-07-01 10:21:17 帮助过:11人阅读
添加一个实值方法,即是程序与数据库之间的协作:
在ASP.NET MVC 的控制器中,添加2个操作,一个是为网页准备,一个是添加Action:
MVC视图:
其中上面#2html代码:
#3javascript程序:
var GoodsApp = angular.module(‘GoodsApp‘, []);
GoodsApp.controller(‘GoodsAdditionController‘, function ($scope, $http) {
$scope.GoodsAddition = function () {
var obj = {};
obj.Item = $scope.Item;
obj.Description = $scope.Description;
obj.Qty = $scope.Qty;
$http({
method: ‘POST‘,
url: ‘/Goods/Insert‘,
dataType: ‘json‘,
headers: {
‘Content-Type‘: ‘application/json; charset=utf-8‘
},
data: JSON.stringify(obj),
}).then(
function success(response) {
if (response.data.Success) {
alert("数据添加成功。");
window.location.href = response.data.RedirectUrl;
}
else {
alert(response.data.ExceptionMessage);
}
},
function error(error) {
alert(response.error.data);
});
};
});
Source Code
实时演示:
[转自:http://www.cnblogs.com/insus/p/6858290.html]
学习Angularjs向数据库添加数据
标签:rip mod har win method data select src null