Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Angularjs Post Data

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 245
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: