Hi,
Today we will discuss how to post data to the MVC Controller through AngularJS.
To do so, you will need to inject '$http' as a dependency while defining your angularJS controller:
app.controller('Controller', ['$scope', '$http', function ($scope, $http) {
}]);
Now to post Data you need to use the below Code Snippet:
var response = $http({
method: 'POST',
url: '/Sample/PostData',
data: { "model": $scope.model }
});
response.success(function (data) {
// Process to be done after the data is posted successfully
});
response.error(function (data) {
// Process to be done in case there is an error while posting
});
where "Sample/PostData" in url variable are the MVC Controller & Action respectively.
$scope.model in data is the data you need to post as a model to MVC Controller.
And here you go, you can now post any data to MVC Controller through AngularJS.
Happy Coding...
0 Comment(s)