When trying to route a core 2.0 application, I can not reach the controller.
public class GetClientController : Controller
{
LoadClient loadClient = new LoadClient();
[HttpGet]
public IEnumerable<Cliente> GetCliente(double cpf)
{
return loadClient.GetCliente().AsEnumerable().ToList();
}
}
In the above controller, RoutePrefix does not scroll, I tried these two namespace and it did not scroll:
using System.Net.Http;
using System.Web.Http;
In my model I did this
[Route("api/getcliente/{cpf}")]
public List<Cliente> GetCliente(Int64 cpf)
{
List<Cliente> cliente = new List<Cliente>();
cliente.Add(new Cliente(123456, "[email protected]", "986754007", "CB", "EML"));
cliente.Add(new Cliente(908734, "[email protected]", "988877731", "CB", "SMS"));
cliente.Add(new Cliente(674300, "[email protected]", "965241131", "PF", "EML"));
cliente.Add(new Cliente(101654, "[email protected]", "987450101", "EX", "EML"));
cliente.Add(new Cliente(501274, "[email protected]", "986754144", "PA", "SMS"));
var lista = cliente
.Where(cp => cp.Cpf == cpf).ToList();
return lista;
}
When I test in postman, it does not give me an error, but I do not get the last list. This is the postman:
EDIT1
Imadethiseditionandremoveditfromthemodelanditdoesnotgointothemethod
publicclassGetClientController:Controller{LoadClientloadClient=newLoadClient();[HttpGet][Route("api/getcliente/{cpf}")]
public IEnumerable<Cliente> GetCliente(Int64 cpf)
{
return loadClient.GetCliente(cpf).AsEnumerable().ToList();
}
}
EDIT3MyStartap.cs
publicclassStartup{//Thismethodgetscalledbytheruntime.Usethismethodtoaddservicestothecontainer.//Formoreinformationonhowtoconfigureyourapplication,visithttps://go.microsoft.com/fwlink/?LinkID=398940publicvoidConfigureServices(IServiceCollectionservices){}//Thismethodgetscalledbytheruntime.UsethismethodtoconfiguretheHTTPrequestpipeline.publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv){if(env.IsDevelopment()){app.UseDeveloperExceptionPage();}app.Run(async(context)=>{awaitcontext.Response.WriteAsync("Hello World!");
});
}
EDIT4
I made this change and it still did not roll
[Route("api/[controller]")]
public class GetClientController : Controller
{
LoadClient loadClient = new LoadClient();
[HttpGet("getcliente/{cpf}")]
public IEnumerable<Cliente> GetCliente(Int64 cpf)
{
return loadClient.GetCliente(cpf).AsEnumerable().ToList();
}
}