I have a angular component:
import { Component } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'search',
template: require('./search.component.html'),
styles: [require('./search.component.css')]
})
export class SearchComponent {
public tumorType = "Tymor Type";
public gene = "Gene";
public searchList: any[];
public searchCriteria:
{
TumorType: string;
Gene: string;
Country: string;
} =
{
TumorType: "Acute Lymphoblastic Leukemia",
Gene: "ABL",
Country: "Australia"
};
constructor(private http: Http) {
}
public search() {
let searchCrit = this.searchCriteria;
this.http.get('/api/RocheClinicalTrial/' + JSON.stringify({ searchCrit })).subscribe(result => {
//this.searchList = result.json();
console.log(result);
});
}
}
and a mvc controller
namespace RocheClinicalTrial.Controllers
{
[AllowAnonymous]
[Route("api/[controller]")]
public class RocheClinicalTrialController : Controller
{
// GET: api/values
[HttpGet]
public JsonResult Get()
{
var repo = new Repository.Repository();
var data = repo.GetData();
return Json(data);
}
[Route("GetData")]
//GET api/values/5
[HttpGet("api/values")]
public string Get(string searchCriteria)
{
System.Console.WriteLine(searchCriteria);
return "value";
}
}
}
This should call the
Get(string searchCriteria)
method. But the call isn't happening. But when I call without value
this.http.get('/api/RocheClinicalTrial/' /+ JSON.stringify({ searchCrit })/).subscribe(result => { //this.searchList = result.json(); console.log(result); });
it calls the
public JsonResult Get()
method. Can you please help.
Here is the call screenshot from network tab
