c# - How to make valid route for {id}/visit? -
i new @ asp.core , try make valid route {id}/visits
my code:
[produces("application/json")] [route("/users")] public class usercontroller { [httpget] [route("{id}/visits")] public async task<iactionresult> getuser([fromroute] long id) { throw new notimplementedexception() } }
but, @ route {id}
generated method same:
// get: /users/5 [httpget("{id}")] public async task<iactionresult> getuser([fromroute] long id) { return ok(user); }
how make route /users/5/visits
nethod?
parameters @ getuser
should add?
name methods differently , use constraints avoid route conflicts:
[produces("application/json")] [routeprefix("users")] // different attribute here , not starting /slash public class usercontroller { // gets specific user [httpget] [route("{id:long}")] // matches users/5 public async task<iactionresult> getuser([fromroute] long id) { // needs done } // gets visits specific user [httpget] [route("{id:long}/visits")] // matches users/5/visits public async task<iactionresult> getuservisits([fromroute] long id) // method name different { // needs done } }
Comments
Post a Comment