I am trying to publish two parameters for the following function, but I am unable to get to the function:
public void SetShopSubCategories([FromBody]string userId, int []subCategories ) { }
This is how I write:
var subCategories = [ 1, 2, 3, 4, 5]; var userId = "123"; $.ajax({ type: "POST", url: "/Category/SetShopSubCategories/", contentType: 'application/json; charset=utf-8', data: JSON.stringify(userId, subCategories), success: function () { alert("OK"); }, error: function () { alert("error"); }
When I send only one parameter, it goes well and I can achieve the function:
public void SetShopSubCategories([FromBody]string userId ) { } var userId = "123"; $.ajax({ type: "POST", url: "/Category/SetShopSubCategories/", contentType: 'application/json; charset=utf-8', data: JSON.stringify(userId, subCategories), success: function () { alert("OK"); }, error: function () { alert("error"); }
It's also good:
public void SetShopSubCategories( int []subCategories ) { } var subCategories = [ 1, 2, 3, 4, 5]; $.ajax({ type: "POST", url: "/Category/SetShopSubCategories/", contentType: 'application/json; charset=utf-8', data: JSON.stringify(subCategories), success: function () { alert("OK"); }, error: function () { alert("error"); }
My RoutConfig:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); GlobalConfiguration.Configuration.Routes.MapHttpRoute( name: "SetCategories", routeTemplate: "{controller}/{action}" ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } );