asp.net mvc - MVC web api with GET and POST Method -
how execute mvc web api method different name type , post. can't able execute. shows error. here code.
webapiconfig.cs
config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { action = "get", id = routeparameter.optional } );
employee controller :
[httpget] public string test1() { return "this test1 string"; } [httpget] public string test2() { return "this test2 string"; } [httppost] public string test3() { return "this test3 string"; }
i want execute both post , method in different scenario. how it?
there 2 ways achieve
- specify different input parameters methods same http method (httpget/ httpost/httpput).
example -
[httpget] public string test1(string input) { return "this test1 string"; } [httpget] public string test2() { return "this test2 string"; }
specify explicit different routes each of method in controller using multiple httpget.
[httpget] [route("~/mycontroller/action")] public string test1(string input) { return "this test1 string"; }
[httpget] [route("~/mycontroller/action2")] public string test2() { return "this test2 string"; }
Comments
Post a Comment