我有這個如何實現另一個變量參數名稱爲路線
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 }
);
}
}
,當我嘗試使用參數一樣
[AcceptVerbs("POST")]
public JsonResult ShowProductsPerPage(string pageNumber)
{ ...
它不工作
但是當我使用
[AcceptVerbs("POST")]
public JsonResult ShowProductsPerPage(string id)
{ ...
這是工作很好。
這裏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);
}
});
我在JavaScript變量pageNumber
使用,所以我想保持相同的名稱後面的方法 代碼。
有沒有可能?
只是改變(編號)到路線{PAGENUMBER }。 – Dennisch
向我們展示如何將數據發佈到控制器 – karaxuna
@Dennisch但是當我使用'id'時,其他方法呢?他們不會工作。 –