How to implement another var parameter name for the route
I have this
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id
= UrlParameter.Optional }
);
}
}
and when I try to use a parameter like
[AcceptVerbs("POST")]
public JsonResult ShowProductsPerPage(string pageNumber)
{ ...
It is not working
but when I use
[AcceptVerbs("POST")]
public JsonResult ShowProductsPerPage(string id)
{ ...
It is working fine.
Here JS
var currentUrl = window.location.protocol + '//' + window.location.host;
var url = currentUrl + "/Products/ShowProductsPerPage/" + pageNumber;
$.ajax({
type: "POST",
url: url,
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.pageNumber);
}
});
I use in JavaScript the variable pageNumber so I'd like to keep the same
name for the code behind methods.
Is it possible somehow?
No comments:
Post a Comment