ajax - How to $http Get call with identifer -


i need make call id identifier. have done angular resource, not $http. new understanding how $http works angular.

angular controller

  $scope.emailpdf = function () {     $http.get('/api/pdf/{id}').success(function () {         $scope.printpreviewmodal();     }); } 

routing

config.routes.maphttproute(             name:"pdfapi",             routetemplate: "api/{controller}/{id}",         defaults: new {controller = "apigeneratepdf", id=routeparameter.optional}         ); 

api controller

      public string get(int id)         {         jobdataadapter adapter = new jobdataadapter();         job job = new job();         job = adapter.getjob(id);         if (job == null)         {             return string.empty;         }          try         { 

error message

{"$id":"1","message":"the request invalid.","messagedetail":"the parameters dictionary contains null entry parameter 'id' of non-nullable type 'system.int32' method 'system.string get(int32)' in 'texasexterior.controllers.pdfcontroller'. optional parameter must reference type, nullable type, or declared optional parameter."} 

updated web config

 config.routes.maphttproute(         name: "pdfapi",         routetemplate: "api/pdf/{id}",     defaults: new { controller = "pdfcontroller", id = routeparameter.optional }     ); 

controller

$scope.emailpdf = function () {     $http.get('/api/pdf/', { id: id }).success(function () {         $scope.printpreviewmodal();     }); } 

error message

referenceerror: id not defined

controller

 var id=1     $scope.emailpdf = function () {     $http.get('/api/pdf?id=id').success(function () {         $scope.printpreviewmodal(); }); 

}

error message

{"$id":"1","message":"the request invalid.","messagedetail":"the parameters dictionary contains null entry parameter 'id' of non-nullable type 'system.int32' method 'system.string get(int32)' in 'texasexterior.controllers.pdfcontroller'. optional parameter must reference type, nullable type, or declared optional parameter."}

controller

var _id = 1; var url = '/api/pdf'; $scope.emailpdf = function () {     $http.get(url, { id: _id }).success(function () {         $scope.printpreviewmodal();     }); } 

error message

{"$id":"1","message":"no http resource found matches request uri 'http://localhost:44301/api/pdf'.","messagedetail":"no action found on controller 'pdf' matches request."} 

how about

  $http.get(url,{id:id}) 

that pass in params second argument call map or string.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -