Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 2 ASP.NET MVC 2分页路由问题_Asp.net Mvc 2_Paging - Fatal编程技术网

Asp.net mvc 2 ASP.NET MVC 2分页路由问题

Asp.net mvc 2 ASP.NET MVC 2分页路由问题,asp.net-mvc-2,paging,Asp.net Mvc 2,Paging,我在分页时出错 我的行动: ProductList(string country, string city, string town, int? pageNumber) 我的路线: routes.MapRoute( "ProductList", "myList/{country}/{city}/{town}/{pageNumber}", new { controller = "Product", action = "ProductList", country="", c

我在分页时出错

我的行动:

ProductList(string country, string city, string town, int? pageNumber)
我的路线:

routes.MapRoute(
    "ProductList",
    "myList/{country}/{city}/{town}/{pageNumber}",
    new { controller = "Product", action = "ProductList", country="", city="", town= "", pageNumber = UrlParameter.Optional });
行动链接:

Url.Action("myList","Product", new{ country="Finland",city="",town="",pageNumber=2 }) 
城市=2

我找到了如下解决方案:

Url.Action("myList","Product", new{ country="Finland",city="s",town="n",pageNumber=2 })
http://myList/Finland/s/n/2

ProductList(string country, string city, string town, int? pageNumber)
{
    city== "s" ? city = null;
    town == "n" ? town= null;

    process...
}
http: /myList/芬兰/2 /myList/芬兰/赫尔辛基/3
/myList/Finland/town/7

您不能跳过该路线中的参数。您不能打电话期望pageNumber的值为2。将第一段中的值指定给管线中的第一个变量。所以2被分配给城市变量。您必须确保pageNumber之前的所有参数均为非空值。

只有路由定义中的最后一个参数是可选的。

这与“mvc”无关。也许是关于某个特定的MVC框架?