Dr.killer
Dr.killer

Reputation: 21

TypeError: Cannot assign to read only property 'method' of 11

i'm beginner in angularjs and now i have a problem. i use angularjs for client side and asp.net c# and web Api for server side.

i want to send an object (or a string variable) web api controller and get a collection of record of my table. but i recieve this error in my browser console:

TypeError: Cannot assign to read only property 'method' of 11.

and this is my code:

angular controller:

$scope.selectedMainCategory = {
    MainCategoryCode: '11',
    MainCategoryName: 'eleven'
};
$scope.getWholeData = function () {
    $http.get("http://localhost:35621/api/SubCategoryApi", $scope.selectedMainCategory.MainCategoryCode)
        .success(function (response) {

        $scope.wholeData = response;

    })
    .error(function () {
        alert("data not found", error);
    });
};

web api controller:

public IEnumerable<sp_SubCategory_SelectAllRecs_Result> Gettb_SubCategory(string MyMainCategoryCode)
    {
        return db.sp_SubCategory_SelectAllRecs(MyMainCategoryCode, "");
    }

('sp_SubCategory_SelectAllRecs' is my sql server stored procedure and 'sp_SubCategory_SelectAllRecs_Result' is my class for result of that SP)

where is my mistake?

Upvotes: 1

Views: 5557

Answers (2)

Sofre Garevski
Sofre Garevski

Reputation: 64

Try to change the url. Possible solution would be:

$scope.getWholeData = function () {
  $http.get("http://localhost:35621/api/SubCategoryApi?code=" + $scope.selectedMainCategory.MainCategoryCode)
  .success(function(data){
    console.log("DATA:",data);
  })
  .error(function(err){
    console.log("ERROR:",err);
  })
}

Then on the server you can handle the code parameter.

Upvotes: 1

Bhaskar Gyan Vardhan
Bhaskar Gyan Vardhan

Reputation: 9227

MainCategoryCode and MainCategoryName should be a string

$scope.selectedMainCategory = {
'MainCategoryCode': '11',
'MainCategoryName': 'eleven'};

Upvotes: 0

Related Questions