1

Trying to place an http.get with parameters:

Angular2 service:

getAvailability(customerId) {
    var Customer = this.Customer.getValue();
    var data = ({ 'customerId': Customer.Id, 'eventId': eventId});
      console.log("service_data_body", data);  
    this.http.get("GetAvailability", data)
        .map(res => res.json()).subscribe((x) => {
            console.log("callback succes");
        });

}

MVC controller:

public ActionResult GetAvailability(int? customerId, int? eventId)
{
    var k = customerId; 
    var l = eventId;
    .......
 //some other implementation code....
}

I am not getting any error on build but on run time. While debugging, console log gives me the values but placing breakpoints, it seems that not been send to C#(var k and var l are null). So, the js service does not passing the variables the appropriate way.

Any help is welcome.

1
  • This is a GET. why does it look like you are trying to send data in the body? try including the data as url parameters. Commented Dec 12, 2016 at 12:37

1 Answer 1

1

This is a GET. why does it look like you are trying to send data in the body? try including the data as url parameters.

getAvailability(customerId) {
    var Customer = this.Customer.getValue();
    var query = "?customerId=" + Customer.Id + "&eventId=" + eventId;
    console.log("service_data_query", query);  
    this.http.get("GetAvailability" + query)
        .map(res => res.json()).subscribe((x) => {
            console.log("callback succes");
        });

}
Sign up to request clarification or add additional context in comments.

1 Comment

Well, i am passing my "criteria", in order to get back an object. So, your solution worked pretty well for me(although I modified it, to encrypt the values in the url). Thank you for your time!

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.