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
Post a Comment