javascript - Add an extra get method in asp.net web api -
javascript - Add an extra get method in asp.net web api -
i'm new comer asp.net web api world. i've got basic understanding of get(), put(), post() , delete.
in application, require 2 more get() method. explanation given below-
public class studentcontroller : apicontroller { public ienumerable get() { //returns students. } //i add together method======================= [httpget] public ienumerable getclassspecificstudents(string classid) { //want homecoming students specific class. } //i add together method======================= [httpget] public ienumerable getsectionspecificstudents(string sectionid) { //want homecoming students specific section. } public pupil get(string id) { //returns specific student. } }
there $http.get(..)
in angularjs controller.
my question is, how can phone call 2 additional get()
methods angular controller.
well, haven't used asp.net mvc in forever. able like:
public class studentcontroller : apicontroller { [route("students")] public ienumerable get() { //returns students. } //i add together method======================= [httpget] [route("students/class/{classid}")] public ienumerable getclassspecificstudents(string classid) { //want homecoming students specific class. } //i add together method======================= [httpget] [route("students/section/{sectionid}")] public ienumerable getsectionspecificstudents(string sectionid) { //want homecoming students specific section. } [route("students/{id}")] public pupil get(string id) { //returns specific student. } }
you specify routes in routeconfig this:
routes.maproute( name: "students", url: "students/class/{classid}", defaults: new { controller = "student", action = "getclassspecificstudents", id = urlparameter.optional } );
you have seek self. , can read more here , here.
not have specified routes can add together angular $http.gets each route.
var url = "whateverdoma.in/students/" $http.get(url) .success() .error() var url = "whateverdoma.in/students/class/" + classid; $http.get(url) .success() .error() var url = "whateverdoma.in/students/filter/" + filterid; $http.get(url) .success() .error()
javascript asp.net-mvc angularjs asp.net-web-api angular-http
Comments
Post a Comment