MVC Api Controllers (Get/ Post)
System.Web.Http.ApiController is one of the controller types in Asp MVC
Default Routing
Any request method like Get, Post, Put, etc can be used with action names started with the method name
ex:
GetEmployees()
GetProducts()
but it checks the input parameters if we use more than one Get or other method names.
When posting to an action like below
public HttpResponseMessage PostApplication(Application_ui param)
public class Application_ui{
public string Action{get;set;};
public int No{get;set;}
}
you should have a class that can be instantiate in parameter and the client side call should match the object properties
if you use json again that should be stringified
$.post("/api/ApplicationAPI/", JSON.stringify({Action:'add', No:'34'}));
Reference
http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-1#sending_simple_types
http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection
Default Routing
routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
Any request method like Get, Post, Put, etc can be used with action names started with the method name
ex:
GetEmployees()
GetProducts()
but it checks the input parameters if we use more than one Get or other method names.
When posting to an action like below
public HttpResponseMessage PostApplication(Application_ui param)
public class Application_ui{
public string Action{get;set;};
public int No{get;set;}
}
you should have a class that can be instantiate in parameter and the client side call should match the object properties
if you use json again that should be stringified
$.post("/api/ApplicationAPI/", JSON.stringify({Action:'add', No:'34'}));
Reference
http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-1#sending_simple_types
http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection
Comments