I am trying to post two parameters to the following function but I dont manage to reach the function:
public void SetShopSubCategories([FromBody]string userId, int []subCategories )
{
}
This is how I post:
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 post only with one parameter it goes well and I can reach 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");
}
This one also goes well:
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 }
);