Reputation: 1483
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.
Upvotes: 1
Views: 819
Reputation: 247018
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");
});
}
Upvotes: 1