c# - WebAPI Controller GetAll or Get some Id -


i have controller this

[route("api/foo/mycontroller/{id}")] public ihttpactionresult get(int id) {    //code code    foo(id); // foo accept int or null } 

this work, if call api/foo/mycontroller/1, needed call api/foo/mycontroller "getall" parameter id null , stuff controller return all, how go there?

you optional parameter:

[route("api/foo/mycontroller/{id}")] public ihttpactionresult get(int? id = null) {     iqueryable foo = getdata();     if (id.hasvalue)     {         foo = foo.where(e => e.id == id.value);     }     //... } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -