0

I want to get angularjs value from AngularController.js to CCharpController.cs

This I want to sum value from $scope.count1 and $scope.count2

`

$scope.onSubmit = function () {
    for (var i = 0 ; i < $scope.Data.length ; i++) {
        if ($scope.Data[i].1 === true) {
            $scope.count1 += 1;
        }
        else if ($scope.Data[i].2 === true) {
            $scope.count2 += 1;
        }
    }
}

`

and pass to CCharp function like this,

`

[Route("api/WarehousePlan/AllowWarehousePlan")]
[HttpPost]
[Authorize]
public IHttpActionResult AllowWarehousePlan([FromBody] WarehouseAllowDenyModel model){ 
    ....
    var count = $scope.count1 + $scope.count2 }

`

I expect receive count value from angularjs function.

2
  • you need to use a service that is calling your api endpoint look here: lullabot.com/articles/processing-forms-in-angularjs Commented Jan 8, 2019 at 8:17
  • You might have to make HttpPost request to API URL with the count value as a parameter, then your C# controller will receive it as an argument. Commented Jan 8, 2019 at 8:20

2 Answers 2

1

First declare a model

$scope.modelVM = {};

Then assign the parameter into model as likes you declare in your model class

 $scope.modelVM.count1 += 1;
 $scope.modelVM.count2 += 1;

After then post the model via http

 $http.post('api/WarehousePlan/AllowWarehousePlan', $scope.modelVM).then(
            function (successResponse) {
                if (successResponse.status == '200') {
                    alert("Data Submit Successfully..");
                }
            },
            function (errorResponse) {
                alert("Not Successful");
            });
Sign up to request clarification or add additional context in comments.

Comments

0

Set value in Cookie in Controller file,

 HttpContext.Current.Response.Cookies["count1"].Value = "1";

You can access cookie value in JS file,

$scope.count1 = $cookies.get("count1");

To Update Cookie value in JS file,

$cookies.put('count1',2);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.